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

nuget

Solution

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)

Problem

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?

Original source