简体   繁体   中英

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 . Unfortunately the servers we are working on don't support .NET Framework 4.5.

When using Nuget Package Manager Console with the Install-Package command we are receiving the following error,

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?

Thanks,

You can't select the .NET version, but you can select the version of the NuGet package:

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. IIRC, it was 4.0.30506 .

So, to install version 4.0.30506, you use the command

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM