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:

\Project
   \Packages
   \OtherStuffForIgnore
   fool.cs

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:

\packages
!\packages\repositories.config

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"?>
<configuration>
  <solution>
    <add key="disableSourceControlIntegration" value="true" />
  </solution>
</configuration>

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 *

Explore More

How To Fix Azure Functions Timer Trigger Unable to Start Running Locally with Vs2022 17 2 X Azurite

Lately my VS2022 (17.2.x) Azure Functions projects started failing to run locally. The local console had errors related to not being able to start any of the Timer Triggers. The

How to get the nuget cache folder location programmatically

While programming if I need to get from a .NET app (not .NET Core app) the list of directories where NuGet stores its packages. Let’s see how to do this.

How can I clear the NuGet package cache using the command line?

You can do this using Visual Studio menu on UI or by using command. You have two ways to do this. Let’s check: First Option: Let’s move with first option,