Friday, September 18, 2015

Resolving NuGet Package Reference problems

If you have numerous NuGet Package References in your project or solution, at one point or another, you will inevitably run into NuGet Package Reference problems.

One of the most common problems with NuGet Packages is ensuring that your NuGet Package References are restored at build time.

This can be corrected by making sure you have this setting in Visual Studio Tools-->Options-->NuGet Package Manager:



The second problem you might run into is that NuGet Package References may differ across your entire solution!  For example, if you have numerous projects in your solution, there is a good chance that they may be using different NuGet Package Reference Assembly Versions!  So how do you manage these discrepancies?

You right click on the solution and select "Manage NuGet Packages for Solution":



This will show you all of the projects in your solution that have NuGet Package References along with their associated installed assembly versions.

 If you are still having problems with differing assembly versions, then you will need to check the packages.config file for each of the different projects:

In the packages.config file you will find all of the various NuGet Package References along with their respective versions.  You will have to compare all of these versions across all of your Visual Studio projects to ensure that they have matching versions.

Lastly, if you are still encountering issues with building packages with NuGet references, then you should close your Visual Studio solution and delete the packages  directory from the root of the solution in Windows Explorer.





Now, you can go ahead and try re-building your Visual Studio solution to restore all missing NuGet Packages to see if your NuGet Package Reference issues are now resolved!

If you are having problems with NuGet Package Versions and you need to re-install a NuGet Package Reference, in Visual Studio 2013 (especially if that NuGet Package has other dependencies), you will have to MANUALLY REMOVE the references from Visual Studio and the referring lines in packages.config.

Then, in NuGet Package Manager in Visual Studio 2013, you can re-install the NuGet packages.

If you are using Visual Studio 2015, however, you have a new option to remove or uninstall the NuGet Packages called "Force uninstall, even if there are dependencies on it":


This removes many of the obstacles present while working with NuGet Package References in Visual Studio 2013 and allows you to effortlessly uninstall and reinstall any NuGet Package References that you need!





No comments:

Post a Comment