CompanyDroneFromSector7G
CompanyDroneFromSector7G

Reputation: 4517

Restrict Dependencies to specific .NET version using NuGet

I have a C# solution targeted for framework 4.5.1 but the server I need to install this on uses 4.0 so I need to roll this back.

The developer has used NuGet (which I'm not really familiar with) for dependency management. I've seen there is a way to request specific versions of each library so I'm hoping there is a feature which allows me to restrict these to a specific .NET version.

How can I get NuGet to install the latest dependencies for .NET version 4, or is this not a feature it supports?

Upvotes: 2

Views: 2456

Answers (2)

Matt Ward
Matt Ward

Reputation: 47937

If you change the target framework of the project then Visual Studio will check the compatibility of the NuGet packages and tell you which ones are compatible or not and whether they need to be reinstalled. You can then reinstall them from the Package Manager console using the -reinstall option.

Update-Package –reinstall <packageName>

NuGet does not directly support a way to restrict or install NuGet packages for a specific .NET version. The NuGet package will either support that .NET version or not. You can restrict a project to a specific version of the NuGet package by using the allowedVersions attribute in the packages.config file but that is independent of the .NET version the NuGet package supports.

Upvotes: 2

Jeremy
Jeremy

Reputation: 3548

Nuget should install packages that are available for the targeted version of .NET

Check your packages folder, or check the documentation of each dependency for support of .NET 4.0
In some cases you may just be able to re-target your application without uninstalling any Nuget packages.

To install a specific version of a Nuget package, you can use the "-Version" flag
Example -

Install-Package AvalonDock -Version 2.0.1320

References -
http://docs.nuget.org/Consume/Package-Manager-Console
http://dutton.me.uk/2013/07/24/how-to-install-a-specific-version-of-a-package-with-nuget/

Upvotes: 2

Related Questions