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:49

Remove the packages.config file within your solution.

查看更多
smile是对你的礼貌
3楼-- · 2019-01-20 22:51

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.

查看更多
Ridiculous、
4楼-- · 2019-01-20 22:55

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

查看更多
戒情不戒烟
5楼-- · 2019-01-20 23:00

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.

查看更多
地球回转人心会变
6楼-- · 2019-01-20 23:00

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>
查看更多
Lonely孤独者°
7楼-- · 2019-01-20 23:02

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.

查看更多
登录 后发表回答