remove nuget package restore from solution

65,620

Solution 1

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

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

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

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

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

Share:
65,620

Related videos on Youtube

Wiebe Tijsma
Author by

Wiebe Tijsma

Developer interested in CQRS, Queues, Buses, codes mostly in C#. #SOreadytohelp

Updated on July 09, 2020

Comments

  • Wiebe Tijsma
    Wiebe Tijsma almost 4 years

    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?

    • Betty
      Betty over 12 years
      Can't you just rollback the changeset in Source control?
    • Wiebe Tijsma
      Wiebe Tijsma over 12 years
      well it was quite a big changeset, but thanks to your comment I did have a look, and it seems it also added a .nuget folder in the solution path, deleted that as well to see if it fixes the problem
    • Baldy
      Baldy about 12 years
      Did you manage to fix the build server? (and is it teamcity?), because the import project line you quote above is what is causing my teamcity builds to fail
    • Wiebe Tijsma
      Wiebe Tijsma about 12 years
      @Baldy No we are using TFS Build and I didn't really look for a solution, just removed it (still planning on diving into it later)
    • deadlydog
      deadlydog over 10 years
      I've created an issue for the NuGet team to fix this problem. Please go up-vote it at nuget.codeplex.com/workitem/3756
    • carmbrester
      carmbrester almost 10 years
      This IFix tool helped me to identify and correct the numerous locations within files that needed to be updated.
  • TimDog
    TimDog about 12 years
    I have found that there's also a <Import Project="$(SolutionDir)\.nuget\nuget.targets" /> at the end of the .csproj file that needs to be manually removed.
  • Wiebe Tijsma
    Wiebe Tijsma about 12 years
    @TimDog that's part of the question :)
  • TimDog
    TimDog about 12 years
    HA! backs away slowly :)
  • Damian
    Damian about 12 years
    This thing has been plaguing me as well. If your projects are in many different solutions the package restore feature causes mounds of problems.
  • Xavier Decoster
    Xavier Decoster almost 12 years
    "Make sure you close the solution" is actually of key importance here, as VS2010 seems to cache csproj/msbuild files (without picking up certain modifications). I didn't notice this behavior in VS2012, but this has plagued me a lot when modifying these files within VisualStudio.
  • Anders Bornholm
    Anders Bornholm over 11 years
    Didn't have to delete .nuget from the folder, but you sure have to close the solution.
  • Diganta Kumar
    Diganta Kumar over 11 years
    Restart VS2010 after modifying all the .csproj file of all the projects in your solution. You can also comment these two lines <Import Project="$(SolutionDir)\.nuget\nuget.targets" /> <RestorePackages>true</RestorePackages>
  • deadlydog
    deadlydog over 10 years
    I've created an issue for the NuGet team to fix this problem. Please go up-vote it at nuget.codeplex.com/workitem/3756
  • deadlydog
    deadlydog over 10 years
    I've created an issue for the NuGet team to fix this problem. Please go up-vote it at nuget.codeplex.com/workitem/3756
  • Wiebe Tijsma
    Wiebe Tijsma over 10 years
    @ShaunRowan well almost a year after posting this question/answer I am using nuget on the (TFS) build server, and it sure beats checking in all packages into source control!
  • Maarten Kieft
    Maarten Kieft about 10 years
    Thanks, for me it was just disabeling that option
  • clairestreb
    clairestreb about 10 years
    There are some cases where one needs to check the packages into source code control and nuget is not allowed.
  • Wiebe Tijsma
    Wiebe Tijsma over 9 years
    It 'sucks', as any other product, if you don't know how to use it and don't make an effort to understand it.
  • Igor N
    Igor N over 9 years
    That's ture, but in my optinion nudged doesn't give you enough control over your project. Also the Nuget GUI needs some serious upgrades. 1. Its not intuitive, 2. Its hard to manage the package 3. Its hard to turn off restore 4. Downloads unneeded packages 5. Sometimes its not able to restore pacakges
  • Wiebe Tijsma
    Wiebe Tijsma over 9 years
    I agree to some extent, though I think it really beats having no package manager at all. Seems like they're working on the serious GUI upgrades for nuget 3.0: blog.nuget.org/20141112/nuget-3.0-preview.html
  • Tresto
    Tresto almost 9 years
    I deleted the packages folder and cleared the package cache to fix my issue. Thanks!
  • angularsen
    angularsen almost 9 years
    I've used the IFix tool with great success in cleaning up repos with many projects. It basically automates these steps. visualstudiogallery.msdn.microsoft.com/…
  • schmoopy
    schmoopy over 8 years
    No, it doesn't update the .proj files after - so the problem returns -- but good to do it here too :-)
  • Erik Bergstedt
    Erik Bergstedt over 8 years
    The .nuget folder is hidden and you need to remove it from the directory not only the project.
  • Mark Vincze
    Mark Vincze about 8 years
    One thing that can make this more convenient - as Nitin answered - a script implemented by Owen Johnson that makes the necessary edits in all csprojs recursively: github.com/owen2/AutomaticPackageRestoreMigrationScript/blob‌​/…
  • Moslem Ben Dhaou
    Moslem Ben Dhaou about 8 years
    The output window shows this while building: Restoring NuGet packages... To prevent NuGet from restoring packages during build, open the Visual Studio Options dialog, click on the Package Manager node and uncheck 'Allow NuGet to download missing packages during build.' it is just a confirmation that this should be the way to go.
  • Michael Freidgeim
    Michael Freidgeim about 6 years
    The answer helped me to solve an opposite problem. The project was created in VS2017 solution and then was copied to different VS2015 solution. And nuget packages for the project were not restored until I not added the sections, that are listed in your answer
  • Wiebe Tijsma
    Wiebe Tijsma about 6 years
    @MichaelFreidgeim glad it helped... Though even in your case I'd still remove the MSBUILD targets and just run 'nuget restore' from the command line, or use some pre-build script.. Using MSBUILD targets to restore packages is fundamentally flawed as you might reference targets in nuget packages that haven't been restored yet. Which build server are you using?
  • Michael Freidgeim
    Michael Freidgeim about 6 years
    We are using TeamCity. The problem is that VS2015 solution Is a legacy monolith, that we prefer not to touch, unless it’s absolutely necessary. Anyway I will check, how safe will be to change restore mode. Thank you for your advise.
  • binki
    binki about 6 years
    This is unrelated to Nuget Package Restore. Old versions of VS had a context menu item for projects titled “Enable Nuget Package Restore” which would make a .nuget/ folder and modify your .csproj to reference a .targets file. You were supposed to commit the nuget.exe to your VCS (eww, unsolving the problem nuget solves!) and ugliness like that. Nowadays, msbuild /restore exists and VS’s built-in package restore. The OP is asking how to remove the old, bad way of doing things—not how to disable VS’s correct built-in package restore support.