简体   繁体   English

有没有办法在Nuget中使用Install-Package时指定.NET Framework Version参数?

[英]Is there a way to specify .NET Framework Version argument while using Install-Package in Nuget?

We are trying to install Microsoft.AspNet.WebApi.Client in a project that's targeting .NET Framework 4.0 . 我们正在尝试在面向.NET Framework 4.0的项目中安装Microsoft.AspNet.WebApi.Client Unfortunately the servers we are working on don't support .NET Framework 4.5. 不幸的是,我们正在处理的服务器不支持.NET Framework 4.5。

When using Nuget Package Manager Console with the Install-Package command we are receiving the following error, 使用Nuget Package Manager ConsoleInstall-Package命令时,我们收到以下错误,

PM> install-package Microsoft.AspNet.WebApi.Client
Installing 'Microsoft.AspNet.WebApi.Client 5.1.1'.
.
.
.
Install-Package : Could not install package 'Microsoft.AspNet.WebApi.Client 5.1.1'. You are trying to install this package into a project that targets '.NETFramework,Version=v4.0', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.

How do we choose the right .NET framework is there a command-line argument where we can mention the .NET version? 我们如何选择合适的.NET框架是否存在命令行参数,我们可以提到.NET版本?

Thanks, 谢谢,

You can't select the .NET version, but you can select the version of the NuGet package: 您无法选择.NET版本,但您可以选择NuGet包的版本:

PM> Install-Package Microsoft.AspNet.WebApi.Client -Version <package version>

So what you'd need to do is to figure out which version was the latest version that supported .NET 4.0. 所以你需要做的是弄清楚哪个版本是支持.NET 4.0的最新版本。 IIRC, it was 4.0.30506 . IIRC,这是4.0.30506

So, to install version 4.0.30506, you use the command 因此,要安装版本4.0.30506,请使用该命令

PM> Install-Package Microsoft.AspNet.WebApi.Client -Version 4.0.30506

Some NuGet packages can contain builds for various different .NET versions (eg .NET 3.5, .NET 4, .NET 4.5, etc.), but ASP.NET Web API 2 only supports .NET 4.5. 一些NuGet包可以包含各种不同.NET版本的构建(例如.NET 3.5,.NET 4,.NET 4.5等),但ASP.NET Web API 2仅支持.NET 4.5。

ASP.NET Web API version 4.0.30506, on the other hand, corresponds to ASP.NET Web API 1 , and IIRC it runs on .NET 4.0. 另一方面,ASP.NET Web API版本4.0.30506对应于ASP.NET Web API 1 ,它在.NET 4.0上运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Nuget安装程序包和网络共享 - Nuget install-package and network shares Nuget Install-Package成功,但没有添加引用到csproj - Nuget Install-Package successful but no reference added to csproj 有条件地指定nuget软件包版本 - specify nuget package version conditionally Nuget 包安装错误:Install-Package Google.Apis.Drive.v3 - Nuget package installation error: Install-Package Google.Apis.Drive.v3 C# NuGet 警告的含义是什么:Package x 已使用 NET Framework 版本恢复 - C# What are implications of NuGet warning: Package x was restored using NET Framework version 有没有一种方法可以在构建时自动安装特定版本的Nuget软件包? - Is there a way to automatically install a specific version of a Nuget Package at build time? 无法在.NET Framework 4.7.2项目中安装Nuget软件包 - Unable to install a Nuget Package in a .NET Framework 4.7.2 project 指定私有 Github Nuget 提要时,使用“dotnet add package -s”安装 Nuget 包失败 - Install Nuget package using "dotnet add package -s" fail when specify private Github Nuget feed 安装包:无法找到包'WebActivator' - Install-Package : Unable to find package 'WebActivator' 如何在自定义NuGet包中为不同版本的.NET框架指定不同的依赖项? - How can I specify different dependencies for different versions of the .NET framework in a custom NuGet package?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM