Exclude NuGet packages from TFS

1 minute read

Everybody knows about NuGet right? Right? Well if you don’t, get familiar with it! NuGet is a package manager for Visual Studio that allows you to automatically restore needed references when you load a solution and run a build. This works wonders in a team environment. Now, you don’t need to worry about a reference path, or if you don’t have the right DLLs. It just restores them for you! There are hundreds of great packages out there already in the official NuGet gallery, but you can also run your own server with your own custom packages. When you install a package, it will install the dependencies for you. And keeping your packages up to date is quick and easy.

It really is a great product. But there is a downside. When you install a package it can get stored into your TFS and then keeps copies of all those required files even though it is unnecessary as they just restore at build anyway. But there is hope. As of NuGet 2.7.2, you can disable source integration of the packages so you do not clutter your source control with files that are not required to have a version history.

  1. Enable Package Restore on Solution: Right click on the solution and you should have this option to restore packages automatically.
  2. Delete Nuget.exe, Nuget.targets. Nuget.config should contain a key that says: “Disable Source Integration” and set to True.
  3. Save your Solution, exit.
  4. Open up the project file in Notepad or your favorite text editor. (vbproj or csproj).
  5. Search and remove all lines that say “Nuget.targets”. There typically is only one. Save.
  6. Delete the contents of the packages folder.
  7. Open your solution in Visual Studio.
  8. Build solution, it should restore all packages.
  9. Check in to TFS. This should exclude all of the packages that were just installed.


NuGet is a very easy to use package manager and streamlines a lot of issues that can occur when working on a project with multiple team members or moving between computers.