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)?

  • Absolutely Yes, because these files are part of your code and your project won't build without them.
    – Sharky
    Aug 4 '16 at 7:16
  • I asked a similar question on SO along time ago. You can also look there for answers: stackoverflow.com/questions/1710027/… :)
    – cwap
    Mar 10 '17 at 7:49
  • I wonder why no one in Maven world ask "should we include 3rd party libs in version control". Find some solid counter-argument for NOT committing libs, though not very convincing. Apr 23 '19 at 10:47

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.

  • 7
    I'm on VS2015 (consider that VS2017 has been released just 3 days before you wrote this answer), and the package folder is present in my solution root. I'm curious about how and when NuGet has changed.
    – Teejay
    May 2 '17 at 21:29
  • 17
    Just installed VS 2017 last week, created a new project yesterday and there is a package directory in my project.
    – Jeremy
    Jul 27 '17 at 17:20
  • 2
    What do you do for CI? do you make it Download all nuget packages again and again? (TBH: I, myself, am very unclear what my opinion is)
    – Tomer W
    Oct 29 '17 at 10:08
  • 1
    There's nuances to nuget now. There's two different ways you reference nuget packages. For non-Core web applications, most of them use package.json, and these create a packages directory for the solution. "Package references" is the new way and its behavior is different.
    – AaronLS
    Sep 12 '19 at 22:17
  • 1
    %HOME% is %USERPROFILE% on Windows.
    – tibx
    Feb 11 at 11:49

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.

  • 2
    How often is nuget.org unavailable?
    – Bartosz
    Jul 25 '18 at 8:30
  • 4
    Probably not very often. But maybe I should have said “unreachable” instead of “offline”. A few years ago, we had an incident at work where an excavator accidentally cut the internet cable to our building. Took more than a day to repair. If we had relied on nuget.org, we wouldn’t have been able to build our projects. (yes, I know, nowadays NuGet caches the packages locally...but not back then) Jul 25 '18 at 15:17
  • I will say build times are much longer when you don't checkin the packages folder because it spends most of the build time retrieving packages during package restore.
    – AaronLS
    Sep 12 '19 at 22:18

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.

  • 20
    I would add that you should keep a version of any 3rd party code used in the project stored safely, in case the 3rd party project is removed, the site hosting it is gone etc. A good place to do that is in your version control repository. That also gives you the opportunity to rollback to a previous version of that code, if needed.
    – Bent
    Nov 3 '15 at 9:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.