Monday, March 20, 2017

Remove Nuget from your solution

If you have installed a package in Microsoft Visual Studio using Manage NuGet Packages, back in the day you might have used "Enable NuGet Package Restore" to make Visual Studio automatically restore these packages.

However, "Enable NuGet Package Restore" is the old way of doing things (technically called MS-build integrated restore). If you don't do that step, you are automatically on "NuGet automatic restore" which is the recommended way of doing things.

Since this is incredibly counter intuitive - when we see the "Enable NuGet Package Restore," that almost sounds like what we need, even though we already have the better option without knowing it - almost everyone has at some point clicked on "Enable NuGet Package Restore." And then, if you're doing any major scale development, you probably have SVN or GIT - do you commit the nuget.exe and other files that the above option adds to your project? I'm guessing you probably did - I would not be surprised. Some of you may not even realize that there is another option.

So how do you undo "Enable NuGet Package Restore" and go back to "NuGet automatic restore." (In)conveniently, Visual Studio has no menu options to do this!

What changes does "Enable NuGet Package Restore" make?

To answer this question, I made a new project in Visual Studio 2013, added a NuGet package - JSON.NET - to the project, and committed this to a local SVN repository. Then I did "Enable NuGet Package Restore" and did a diff for changes. Here's my change-log:
  1. This adds the ".nuget" folder, with files "NuGet.exe," "NuGet.config," and "NuGet.targets" to the solution. So the .sln is updated, and the above folders and files are made.
  2. It also adds the following changes to the .csproj file:

If you you have multiple projects in your solution, such entries can exist in more than one .csproj files, depending on whether you added NuGet packages to them or not. 

Hence to remove MS-build integrated restore

And so, to remove "Enable NuGet package restore" from your solution, basically unwind the effects of the above changes.
  1. Delete the .nuget foldler and all its contents from your solution. 
  2. Remove the NuGet added XML for , and tabs. Note that in the above I also have the element attributed to NuGet. This seems to be the case - this element also gets inserted by NuGet. And while its removal may not be essential to migrating to new style package management, I have removed this at least a few times from various projects, without issues.


No comments: