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.
- A nuget.config file containing the disableSourceControlIntegration setting.
- 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.
- Delete everything in my packages folder.
- Make sure TFS doesn’t have any changes around that folder pending.
- Close Visual Studio.
- 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:
- Get TFS to ignore NuGet packages folder
- Unlocking files and folders locked by some employee on TFS
- How can I clear the NuGet package cache using the command line?
- How to get the nuget cache folder location programmatically
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.