如何使用 .net Framework 4.5 使用 netstandard2?

问题描述

我正在尝试安装包 WebSocketSharp.Standard,但出现安装错误

安装包:无法安装包“WebSocketSharp.Standard 1.0.3”。您正在尝试将此包安装到以“.NETFramework,Version=v4.5”为目标的项目中,但该包不包含任何程序集 与该框架兼容的引用或内容文件。有关更多信息,请联系软件包作者。 在行:1 字符:1

安装包 WebSocketSharp.Standard -Version 1.0.3

CategoryInfo : NotSpecified: (:) [Install-Package],InvalidOperationException FullQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PowerShell.Commands.InstallPackageCommand

我下载了 NuGet 并解压缩,我只检查了 netstandard2.0 库

enter image description here

如何在当前项目中使用该包?我使用的是 VS2013。

解决方法

.Net 标准 2.0 支持从 .net 框架 4.6.1 开始工作,但您会得到很多 system DLLs next to your app。所以使用 .net 4.8 而不是 4.6.x。

minimum requirement to use .net standard libs 是使用 Visual Studio 2015(带有更新 3 + 一个 special hotfix),但最好使用 VS2017 或 2019:

如果您只需要使用 .NET Standard 2.0 库 项目,您也可以在 Visual Studio 2015 中执行此操作。但是,您 需要NuGet client 3.6 or higher installed

所以你的 VS2013 太旧了。