Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NuGet package restore - .nuget folder in solution - Commit to repository?

Tags:

nuget

When enabling NuGet package restore, it adds the following to my solution:

/.nuget
/.nuget/NuGet.exe
/.nuget/NuGet.targets

As these are part of my solution, committing the solution to my repository without either of these files means I'll have missing references in my solution, but removing the folder or either of these files means NuGet package restore is not enabled.

Given that part of the point of setting up package restore is so that I don't have to commit binaries to the repository, what is the intention behind forcing NuGet.exe into the solution?

Is the assumption that committing one small .exe to the repository is a small price to pay to remove the need to commit other binaries? Or am I supposed to exclude these from the repository also and tell a developer checking out my repository for the first time to go and enable package restore? What about when continuous integration encounters a missing reference in my solution?

like image 422
Nathan Ridley Avatar asked May 11 '12 04:05

Nathan Ridley


People also ask

Do I need .NuGet folder?

nuget folder is used as a cache for packages downloaded to speed up project restore and compilation. It can safely be removed.

Where are NuGet packages restored to?

Config file, at %AppData%\NuGet\ on Windows, or ~/. nuget/NuGet/ on Mac/Linux. This setting also enables the Restore NuGet Packages command on the solution's context menu in Visual Studio, .

Where is Package Manager console in VS 2019?

Open the project/solution in Visual Studio, and open the console using the Tools > NuGet Package Manager > Package Manager Console command.


1 Answers

The point behind committing the .nuget folder to the repository is that you can set up your solution to use package restore, using the exact same version of nuget.exe you installed when enabling this feature.

Your project files depend on the nuget.targets MSBuild instructions that use nuget.exe, and both files are considered linked together because the MSBuild instructions use the nuget.exe API. It's perfectly possible to end up with a different version of nuget.exe and nuget.targets one day. It uses the NuGet.Build and NuGet.Commandline packages under the hood. That's also the reason why package restore is typically set up once for the solution, and not by every developer individually.

Also, you won't need to install nuget.exe on each build server, and your build server can build solutions with different versions of nuget.exe, which is an added benefit that requires no additional effort. And yes, one could consider it a small price to pay as well :-)

If your CI encounters a missing reference, check the following:

  • your build server cannot reach the NuGet package source
  • your build server cannot find the NuGet package on the NuGet package source (check whether it's there or whether you're pointing to the correct package source)
like image 66
Xavier Decoster Avatar answered Sep 22 '22 03:09

Xavier Decoster