A short time ago I posted a question on Twitter about whether people who use NuGet check the actual packages into source control.Â There werenâ€™t many answers one way or the other, but a lot of people were curious about an answer.Â After some trial and error and experience, I can say this conclusively:
Do not check your NuGet packages into source control.
There are several reasons for this:
- Doing so violates one of the concepts of NuGet, which is to easily manage the latest versions of dependencies.
- Checking in packages greatly increases the size of the repository.
- By default, TFS ignores DLLs, but will check in manifest files.Â This causes problems on build servers, since NuGet looks for the manifest, and if it finds one, wonâ€™t try and pull the package.Â The dependencies you need donâ€™t get deployed.
Here’s the right way to handle this:
- Right-click on your solution and select Enable NuGet Package Restore.
- Add your NuGet packages to your solution, if you haven’t done so already.
- Make sure packages.config is included in your solution, and is committed to source control.
- Make sure your packages folder and repositories.config are included in source control, but ignore the individual package folders.
- Re-read Step 4.Â The key thing here is you want to ignore the folders for the individual NuGet packages.Â This can be tedious with a lot of packages, so sometimes a GUI is nice.
Now, when you go to build your solution, the packages you reference will be pulled fresh by the build server.