Monday, August 13, 2012

Disable NuGet Package Restore

Enabling the NuGet  package restore feature is easy. Just right click on your solution inside Visual Studio and choose the 'Enable NuGet Package Restore' option.

However what if you want to disable this again? I couldn’t find an option to do this, so let’s investigate all the changes that this option made.

First it added a .nuget folder containing a nuget.targets file and nuget.exe. So we’ll start by removing this folder and all its content from your solution.

Second it added an import to this target file to all your projects that are using NuGet packages. To remove this import right click on each project and choose unload project. Right click then on the csproj file and choose the Open with… option from the context menu. Choose the XML editor to edit the file. Browse the following line and remove it from the csproj file:

<Import Project="$(SolutionDir)\.nuget\nuget.targets" /> 


We are not there yet. There is one other change that is done to your projects: an extra property is added called ‘RestorePackages’. So we have to remove the following line from all csproj files:



<RestorePackages>true</RestorePackages> 


Remark: Do all these changes in one run. Otherwise Visual Studio will re-add all this information once you reload the project file.

11 comments:

jkappers said...

Thanks for posting this! Now, I can have successful TFS build again.

Anonymous said...

Thanks for the tip. I missed the last step which led to many frustrating edits of the project files over and over again!

Wal said...

thanks very much. i decided to check my binaries into mercurial as it makes switching between different branches/versions easier later on and its one less dependency on a third party site.

Anonymous said...

Even simpler... Uninstall the damn NuGet package... it is not worth the pain

Anonymous said...

I just needed to do this today since Enable Package Restore is not needed anymore, Thanks!

Andrei Nitescu said...
This comment has been removed by the author.
Andrei Nitescu said...
This comment has been removed by the author.
Andrei Nitescu said...
This comment has been removed by the author.
Anonymous said...

it's the Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild" which also needs to be removed from .csproj

Anonymous said...

Thanks a lot! I accidentally clicked this option and even undo from TFS didn't solve it. After removing the folder I finally got rid of it.

Anonymous said...

Nuget sucks. Just remove nugets and remove or comment package elements from packages.config in root directory of the projects where this is a problem. Use direct references into some lib folder instead.