remove nuget package restore from solution

Visual Studio-2010Visual StudioMsbuildNuget

Visual Studio-2010 Problem Overview


I added the recent nuget package restore feature to a solution using 'Enable NuGet Package Restore': http://docs.nuget.org/docs/workflows/using-nuget-without-committing-packages

However it broke my build server and I didn't have the time to fix it, so I wanted to remove it. There's no option for that as far as I know, so I removed the following line manually from all my *.csproj files:

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

The problem now is that every time my *.csproj files are checked out or open my solution, the line is automatically added again, breaking my build if I accidentally check it in :(

Any ideas how I can remove it permanently?

UPDATE: despite the answer below it still keeps coming back when opening the solution, anyone with the same problem?

Visual Studio-2010 Solutions


Solution 1 - Visual Studio-2010

I didn't look very well, there's another property added to the project files:

<RestorePackages>true</RestorePackages>

Just have to remove this as well as all these lines manually from all *.csproj files:

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

UPDATE:

Turns out it's a persistent little bugger, if you're manually editing your project files, make sure to close the solution and delete all the lines from the project at once, otherwise they're just added again once the project reloads...

UPDATE2:

Delete the .nuget folder from the solution root too

UPDATE3:

A later version of NuGet adds another section that you need to remove:

 <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
    <PropertyGroup>
      <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>
    </PropertyGroup>
    <Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
  </Target>

Update4

Inside the NuGet.Targets located in the .nuget folder, there is another section that gets added to new projects... switch it to false.

<!-- We need to ensure packages are restored prior to assembly resolve -->
<BuildDependsOn Condition="$(RestorePackages) == 'false'">
    RestorePackages;
    $(BuildDependsOn);
</BuildDependsOn>

Solution 2 - Visual Studio-2010

To disable Nuget Package Restore:

  1. Delete .nuget folder
  2. Remove specific lines from all .csproj files

Lines to remove:

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

Note: Make sure you do all changes in one go before reloading solution or else it will add them back.

This is based on the following article: http://bartwullems.blogspot.no/2012/08/disable-nuget-package-restore.html

Also, you might want to double-check that this option is disabled: http://docs.nuget.org/docs/workflows/using-nuget-without-committing-packages

Solution 3 - Visual Studio-2010

Isn't it this setting here?

Options... -> Nuget Package Manager -> [uncheck] Allow Nuget to download missing packages

enter image description here

I'm using Visual Studio Professional + Resharper 8.2

Solution 4 - Visual Studio-2010

Solutions currently using MSBuild-Integrated package restore can be migrated to Automatic Package Restore. From what I understand, this should help those who are encountering CI build issues. (Please correct me if I am mistaken).

Please refer to the document on the nuget website: Migrating MSBuild-Integrated solutions to use Automatic Package Restore at http://docs.nuget.org/docs/workflows/migrating-to-automatic-package-restore

There is information there for converting with and without TFS.

David Ebbo also posted some information at http://blog.davidebbo.com/2014/01/the-right-way-to-restore-nuget-packages.html

Solution 5 - Visual Studio-2010

We actually have a blog post about it and at the end of the post a powershell script was mentioned to help with the migration.

http://docs.nuget.org/docs/workflows/migrating-to-automatic-package-restore

Solution 6 - Visual Studio-2010

NuGet has a blog post about migrating to automatic package restore: http://docs.nuget.org/docs/workflows/migrating-to-automatic-package-restore

There is a powershell script referenced in the blog post that will take care of removing the necessary lines automatically (and recursively): https://github.com/owen2/AutomaticPackageRestoreMigrationScript/blob/master/migrateToAutomaticPackageRestore.ps1

Offering a Disable NuGet Package Restore option directly is marked as Won't Fix: https://nuget.codeplex.com/workitem/1883

Solution 7 - Visual Studio-2010

I followed the accepted solution to no avail using 2012. This did work though,

  1. Completely close the VS
  2. Update the <RestorePackages>true</RestorePackages> to <RestorePackages>false</RestorePackages> and delete the <Import Project="$(SolutionDir)\.nuget\nuget.targets" /> line
  3. Also renamed the nuget.exe to nuget.exe.NotExe

Solution 8 - Visual Studio-2010

For anyone still needing to clean up a project using the old style NuGet package restore, the IFix tool available here automates the process.

Just run the installer (IFix will be added to PATH) and then run the following:

IFix nugetrestore --fix

You can run it in check mode first to see what it will clean up:

IFix nugetrestore --check

Solution 9 - Visual Studio-2010

I had the same issue. What I ended up doing:

  1. go into each project .csproj file in the solution, open it in notepad then removed the portion of the xml and saved.

2)Then I removed the all of the package.config files in the entire solution.

3)Then I had to remove the .nuget and package folders.

At this point, I had a completely NuGet free solution.

4)Then I manually referenced any needed DLLs and hit compile and the solution ran like a champ without the NuGet packages being needed.

Solution 10 - Visual Studio-2010

Go to your solution directory where you have [$(SolutionDir)\.nuget\nuget.targets] .nuget folder and nuget.targets file under it delete the folder, and change remove lines from your csproj for once last time.

The problem won't come back to bug you again.

Solution 11 - Visual Studio-2010

Remove the packages.config file within your solution.

Solution 12 - Visual Studio-2010

I accidentally enabled this "package restore" option while opening my project in VS2012 RC and started getting errors that looked something like:

"Error 1 Unable to locate 'C:\FolderX\SomeProject.nuget\nuget.exe'"

To fix the error I followed the above instructions, opened open each project file in notepad and removed that RestorePackage line.

Solution 13 - Visual Studio-2010

I was able to resolve this issue by taking these steps:

  1. make sure you take a backup of all your current checked-out files changes.

  2. physically delete the solution folder from your C:\ (path that is mapped to TFS).

  3. get latest from TFS for your solution.

  4. copy (if any) your changes from the backup you took in step-1.

hope that helps !

Solution 14 - Visual Studio-2010

I ran into the exact same problem and tried to remove all .nuget and RestorePackage tags from the project files but one project just wouldn't reload not matter how thoroughly I examined it for .nuget and RestorePackages tags. I guess there's some hidden references to this somewhere.

In the end it was easier to just copy the files and create a new project and import it to the solution.

Solution 15 - Visual Studio-2010

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.

<?xml version="1.0" encoding="utf-8"?>
  <packages>
    <!--<package id="EntityFramework" version="6.0.2" targetFramework="net45" />-->
  </packages>

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionWiebe TijsmaView Question on Stackoverflow
Solution 1 - Visual Studio-2010Wiebe TijsmaView Answer on Stackoverflow
Solution 2 - Visual Studio-2010angularsenView Answer on Stackoverflow
Solution 3 - Visual Studio-2010oradView Answer on Stackoverflow
Solution 4 - Visual Studio-2010James BradtView Answer on Stackoverflow
Solution 5 - Visual Studio-2010Dan LiuView Answer on Stackoverflow
Solution 6 - Visual Studio-2010Nitin AgarwalView Answer on Stackoverflow
Solution 7 - Visual Studio-2010DarylView Answer on Stackoverflow
Solution 8 - Visual Studio-2010Simon FoxView Answer on Stackoverflow
Solution 9 - Visual Studio-2010Andy30acreView Answer on Stackoverflow
Solution 10 - Visual Studio-2010arvindView Answer on Stackoverflow
Solution 11 - Visual Studio-2010LatencyView Answer on Stackoverflow
Solution 12 - Visual Studio-2010Dmitry LyalinView Answer on Stackoverflow
Solution 13 - Visual Studio-2010RajeshView Answer on Stackoverflow
Solution 14 - Visual Studio-2010PeterView Answer on Stackoverflow
Solution 15 - Visual Studio-2010Igor NView Answer on Stackoverflow