remove nuget package restore from solution

2019-01-20 22:29发布

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?

15条回答
放荡不羁爱自由
2楼-- · 2019-01-20 22:43

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

查看更多
等我变得足够好
3楼-- · 2019-01-20 22:43

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

查看更多
相关推荐>>
4楼-- · 2019-01-20 22:44

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.

查看更多
▲ chillily
5楼-- · 2019-01-20 22:47

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 !

查看更多
Evening l夕情丶
6楼-- · 2019-01-20 22:48

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
查看更多
我只想做你的唯一
7楼-- · 2019-01-20 22:48

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
查看更多
登录 后发表回答