83

In a C# or VB.NET project, should we include the PACKAGE folder (NuGet package folder that is created in the root of my project that contains the nupkg files and other content) to our source control repository (Git for instance)?

Glorfindel
  • 3,167

4 Answers4

59

It depends.

Check out Bart van Ingen Schenau's answer to determine if it's possible to ignore the packages folder at all.

Basically: yes, NuGet is designed so that you can ignore the packages folder and NuGet will pull everything from the Internet if it's missing.

But should you ignore it? I say: it depends.
IMO it's a question of "can we continue working in case the package repository is not available" (be it temporarily or permanently)

For my personal OSS projects, I have the packages folder ignored in all of them.
When nuget.org is offline, I'll just wait and continue another day.

But it's something different at work.
Sure, you probably still have the packages locally on some machine, but is saving some space worth the hassle when your builds are breaking because your build server can't reach nuget.org?

We decided that space is cheap and we don't want the hassle, that's why we're committing the packages folder to source control.

43

A lot of time has passed, and NuGet has changed, so here's a new answer.

NuGet no longer creates a packages folder inside your source structure. Instead there is one in your user directory (%USERPROFILE%\.nuget\packages on Windows, to be specific) where it puts all packages it downloads, and projects just reference these.

So the simple answer these days is no, you shouldn't. If you are worried about packages you need disappearing, you should create a local NuGet mirror that you back up separately.

32

The basic rule for what goes into a source control repository is that you store there everything related to a project that you need to be able to build, test, deploy and execute the project and which can not be generated from items already present in the repository.

In other words, if you can throw away the PACKAGE folder and its contents without affecting your ability continue working on the project (the build might take longer, but you don't have to hunt down and install anything yourself), then the folder can be safely left out of the repository.
If the folder contains 3rd-party packages that might take a long time to download or that might become unavailable, then that might be a reason to add them to your repository anyway.

1

My stable datum is: "does it compile or not?"

So I created a VS2022 WinForm app on pc 1

I added a NuGet package NPGSQL v7.0

I compile ok and the app runs ok

I push to GIT without package folder

I clone my app on pc 2

I compile the app on pc 2 and compilation is ok

Package folder was created during compilation on pc 2

And the app on pc 2 runs ok

So I don't need to add the package folder to GIT

In your application root folder you should have a packages.config file if you have added NuGet package which lists all the packages which are used in your application so when you compile your application, the compiler will download all packages needed for your app with the correct version.