[ACCEPTED]-Retargeting solution from .Net 4.0 to 4.5 - how to retarget the NuGet packages?-.net-4.5
NuGet 2.1 offers a feature that makes this a lot 9 simpler: just do update-package -reinstall -ignoreDependencies
from the Package Manager 8 Console.
NuGet 2.0 doesn't handle re-targeting your 7 applications very well. In order to change 6 your packages' target frameworks, you must 5 uninstall and reinstall the packages (taking 4 note of the packages you had installed so 3 that you can reinstall each of them).
The 2 reason packages must be uninstalled and 1 reinstalled is:
- When installing a package, we determine the target framework of your project
- We then match that up with the package contents, finding the appropriate \lib\ folder (and \content\ folder)
- Assembly references are added with Hint Paths that point to the package's \lib\ folder, with the right subfolder (\lib\net40 for example)
- Content files are copied from the packages \content\ folder, with the right subfolder (\content\net40 for example)
- We record the targetFramework used to install the package within the packages.config file
- After you change your project's target framework, the Hint Paths still point to net40
- When you uninstall packages, we check the targetFramework that was recorded in packages.config to see what target framework's libs/content to remove from your project
- When you reinstall the package, we detect your updated target framework and reference/copy the right libs/content
For those who had problems with update-package -reinstall <packagename>
command, consider 5 running it with -ignoreDependencies
flag, like this:
update-package -reinstall <packagename> -ignoreDependencies
This flag 4 will leave your package dependencies alone, otherwise 3 they might got updated even if the package 2 you originally wanted reinstall still keeps 1 it's version in same.
More info here.
After trying the accepted answer unsuccessfully 2 I would like to suggest a less risky command:
Update-Package <PackageName> -ProjectName <ProjectName> -Reinstall -IgnoreDependencies
For 1 more info: http://blog.nuget.org/20121231/a-quick-tutorial-on-update-package-command.html
Whilst attempting to reinstall packages 17 solution wide, I encountered a dependency 16 error (in spite of using the -ignoreDependencies
flag), and 15 all the packages.config files for every project had been 14 deleted. In VS2013, it seems that packages.config does 13 not get flushed back to disk and re-added 12 until all the upgraded dependencies/references 11 are re-attached to the project.
In my case 10 what worked was to upgrade each project 9 one-at-a-time by adding the -ProjectName
projectname to the update-package
command. In 8 this case the packages.config is updated as each project 7 is upgraded.
May not be practical for very 6 large solutions but it seems a reasonable 5 compromise to still take advantage of the 4 automated upgrade for as many projects as 3 possible and isolate the problematic ones 2 without having every packages.config in your solution deleted 1 on failure.
With Visual Studio for Mac 2019, right-clicking 7 the Packages folder shows 'Retarget' option 6 in the menu. This resolved the retarget 5 issue for all packages in the project that 4 required retargeting. Looks like there was 3 no NuGet Package Manager under Tools menu 2 in Visual Studio for Mac (atleast in mine), so 1 I couldn't launch Package Manager Console.
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.