Get TFS to ignore NuGet packages folder

We have to tell both NuGet and TFS to ignore the packages, because NuGet is trying to do source-control related stuff that it absolutely shouldn’t be doing. So, you have to do two things.

First Option:

First, add a file named .tfignore to the solution folder (note the lack of s after the tf). Its contents should be as follows:


This tells TFS to ignore the package folder. You might think that this would also ignore the repositories.config file. But that’s not the case but why?
Microsoft’s approach is strange and mysterious. Actually, I think this is part of the NuGet described below, but if this is fixed in the future and you want to keep the repositories.config file instead of having VS regenerate it, you should use the following can There are:


OK, so now thanks to our .tfignore file, TFS is ignoring your packages. Everything is fine, right? No its WRONG, because NuGet is mucking around with your source control and adding the packages to your pending changes. So now let’s tell NuGet to cut it out already.

Second Option:

Create a folder called .nuget in the root of your solution folder. Now, create a file called NuGet.config, and put it in this new folder.

  1. nuget.config file containing the disableSourceControlIntegration setting.
  2. A version of the NuGet Visual Studio 2015 Extension that respects the disableSourceControlIntegration setting (versions from 3.2 onward will work)

The nuget.config file contents should look like, as it is given below:

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

Now your packages should stay out of source control. Just remember to add the NuGet.config and .tfignore files to source control so they never get lost.

People also report that the .tfignore option was NOT working with the nuget.config setting it might be of interest – I followed following steps and it finally worked for me.

  1. Delete everything in my packages folder.
  2. Make sure TFS doesn’t have any changes around that folder pending.
  3. Close Visual Studio.
  4. Re-open VS and reload your solution – using NuGet restore to re-populate packages Note no changes are pending for TFS source control.

Check More:

I hope you enjoyed reading this post. For more information you can check out Microsoft learn.

For more information you can visit our C# Section for more such posts.

Leave a Reply

Your email address will not be published. Required fields are marked *