A Tip for Ignoring NuGet Packages Folder in Visual Studio

2017/01/052 min read
bookmark this
Responsive image

Table of Contents

  1. Introduction
  2. Steps
  3. Result
  4. Bonus: For Git Users
  5. Conclusion

Introduction

When you build a solution in Visual Studio, NuGet restores packages and downloads DLLs into a packages folder. You should not check these files into source control — they can be restored automatically, and committing them bloats your repository.

This guide shows how to properly ignore the NuGet packages folder when using TFS (Team Foundation Server) as your source control.

Steps

1. Create the .nuget Folder

At the root of your Visual Studio solution, create a .nuget folder and add a NuGet.config file inside it.

2. Create the .tfignore File

At the root of your Visual Studio solution, create a .tfignore file.

Your solution structure should look like this:

MySolution/
├── .nuget/
│   └── NuGet.config
├── .tfignore
├── MySolution.sln
├── MyProject/
└── packages/          ← This folder will be ignored

3. Add NuGet.config Content

Inside .nuget/NuGet.config, add the following to disable source control integration for the packages folder:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <solution>
    <add key="disableSourceControlIntegration" value="true" />
  </solution>
</configuration>

4. Add .tfignore Content

In the .tfignore file, add the packages folder path:

\packages

Result

After adding these two files, when you check in your changes via TFS, files and folders under the packages directory will no longer appear in your Pending Changes window.

Bonus: For Git Users

If you're using Git instead of TFS, add this line to your .gitignore file:

packages/

Most Visual Studio .gitignore templates already include this by default.

Conclusion

File Location Purpose
NuGet.config .nuget/NuGet.config Disables NuGet source control integration
.tfignore Solution root Tells TFS to ignore the packages folder

This simple setup keeps your repository clean and avoids unnecessary package files in source control.