Disabling NuGet Package Restore

Yes, this is counterproductive and a step backwards, but if you are working in an environment where your build/proxy server doesn't allow NuGet Package restore then you will need to disable it. This may sound straightforward and something that should be easily supported by NuGet, but I'm afraid you are out of luck. To disable NuGet package restores, you will need to perform some manual changes to your .csproj files.

To fully remove package restore just follow the steps below:


    Before performing any project file changes, you will need to close down the solution in Visual Studio. Visual Studio is sometimes notorious as it seems to cache .csproj files and your changes will be overwritten, unless the solution is shut down.


    When you enable package restore at solution level, a .nuget folder is added at the root level of the solution. Delete this folder.


    Open each .csproj file in the editor of your choice and remove the following settings:

<Import Project="$(SolutionDir)\.nuget\nuget.targets" />  
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">  
      <ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them.  For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
    <Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />

Now you can re-open the solution again and perform a build to ensure that everything is working as expected.

NOTE: Remember to check-in/commit your changes to the version control server as well.

Happy coding... :)


Read more posts by this author.

Subscribe to The Magics

Get the latest posts delivered right to your inbox.

or subscribe via RSS with Feedly!