Get TFS to ignore my packages folder

TfsNuget

Tfs Problem Overview


I'm trying to get TFS (2013) to ignore my packages folder. I passionately don't want it source controlled as I'm using NuGet and it's great!

I've tried cloaking (doesn't seem to work), I've tried adding .tfignore files - nothing is ignored. Why don't the TFS team just add an option to permanently ignore a folder or file like lots of the Subversion clients do?!

Tfs Solutions


Solution 1 - Tfs

Here's the deal: 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 (bad form, Microsoft!). So you have to do two things.

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

\packages

That tells TFS to ignore your packages folder. Now, you would think that this would also ignore the repositories.config file. But it won't. Why? Who knows, the ways of Microsoft are strange and mysterious. Actually, I think it's part of the NuGet stuff I outline below, but if that ever gets fixed in the future and you want to keep the repositories.config file instead of letting VS regenerate it, you should be able to use this:

\packages
!\packages\repositories.config

OK, so now thanks to our .tfignore file, TFS is ignoring your packages. Everything is fine, right? 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.

Create a folder called .nuget in the root of your solution folder.1 Now, create a file called NuGet.config, and put it in this new folder2. Its contents should look like this:

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

And 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.

EDIT: If you're having issues, you may want to delete your packages folder, check in that change, and then go through the steps above.

ALSO EDIT: It looks like this won't happen with newer versions of Nuget. So maybe if you switch to VS/TFS 2017 this issue will clear up without jumping through the above hoops.

1. Add the folder using Source Control Explorer; right-click the solution->Add folder->.nuget
2. When I figured this out using VS 2013, I found the NuGet.config had to go in the .nuget folder. Even if you already have a NuGet.config file in the root of your solution folder (because, say, your company has an internal nuget feed). However, some in the comments have indicated that it works fine in the solution root in VS 2015. Personally, I switched to using TFS in git mode, so I can't test. Additionally, if you do have a custom feed, ensure that you have both the custom feed and nuget.org as keys in the Nuget.config file, or sometimes TFS will randomly decide it can't restore the packages.

Solution 2 - Tfs

An alternative solution to the above is the following.

  • Add the packages folder to TFS (without any files or sub-folders)
  • Right Click the Packages Folder
  • Left Click Advanced
  • Click Cloak

It is worth noting that this solution would need to be applied per TFS workspace. It has worked far more reliably for me rather than using the .tfignore file.

You can read more about this approach in the blog article Prevent TFS from adding installed NuGet packages to source control.

Solution 3 - Tfs

for people reporting that the .tfignore option wasn't working with the nuget.config setting it might be of interest - these steps 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 VS
  4. Re-open VS, and reload solution - using Nuget restore to re-populate packages Note no changes are pending for TFS source control

Solution 4 - Tfs

Add a nuget.config file in a .nuget folder in your solution. Add the following to the nuget.config file:

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

The disableSourceControlIntegration is what makes the trick for TFS Version Control.

Solution 5 - Tfs

You need to be using local workspaces for .tfignore to work. The .tfignore file must be in the folder that contains the files or folders you want to ignore.

So if your solution structure looks like this:

\Project
   \Packages
   \OtherStuff
   foo.cs

You'd put your .tfignore file in \Project:

\Project
   \Packages
   \OtherStuff
   foo.cs
   .tfignore

The contents of the .tfignore in your case would be:

\packages

Here's some documentation for you: http://msdn.microsoft.com/library/vstudio/ms245454(v=vs.110).aspx#tfignore

Solution 6 - Tfs

You can permanently set this once-off in your AppData\Roaming for all solutions (old & new)!

In your %AppData%\NuGet\NuGet.Config file, add the following just before the </configuration> XML tag...

<config>
  <add key="repositoryPath" value="C:\NuGetPackages" />
</config>
<solution>
  <add key="disableSourceControlIntegration" value="true" />
</solution>

...you can specify any path you want - the important thing is putting it OUTSIDE your TFS workspace!

Now you never have to worry about that stuff again. Your solution folder will not contain any packages anymore; all solutions will default to using your custom packages location instead.

NOTE - This works is on a per-user basis.

Solution 7 - Tfs

Set your solution to restore on build, the package folder and packages file will be checked in but the packages won't.

Solution 8 - Tfs

If you are using Git with TFS you need to add a ".gitignore" file. You can do this in "team project | Settings | 'add ignore file'". Then open the file and uncomment the built in ignore statement for Nuget Packages.

If you are using TFVC and you have Local Workspaces configured you can use the ".tfignore" file that honours an identical format to the Git file. I think you need "packages/".

Solution 9 - Tfs

This didn't work for me quite on visual studio online and VS2013.

  • Right Click Solution > Enable NuGet Package Restore. This will add the Nuget.config file to solution

enter image description here

  • Add the .tfignore. I normally do this by adding a text file to the solution root, letting it detect that and then exclude by clicking 'detected add' > right click ignore.

enter image description here

  • Add the packages to .tfignore and tell it to include repositories.config

enter image description here

From the other comments it seems your milage may vary at this point. This is what I do:

  • Check everything in, including any packages.

  • Delete all packages in your solution and then check in this change (this will remove the packages from TFS)

  • Open the solution and build which will add the packages to the project but TFS will not pick them up.

Solution 10 - Tfs

The solution that worked for me was to create both a .tfignore and the following setting in the Nuget.Config:

<configuration>
  ...
  <solution>
    <add key="disableSourceControlIntegration" value="true" />
  </solution>  
  ...
</configuration>

My .tfignore contains this line:

\packages

[I'm using Visual Studio 2015 Update 2]

This is not ideal, and is currently logged as an open issue on github/nuget:

Make it easier to omit packages from TFVC #493

Solution 11 - Tfs

Terje's answer doesn't work all the time for me, sometimes it will work for a while, but then it will pend a load of "adds" for me all over again.

The only way I have found to solve this permanently is to Cloak the packages folder in my Workspace.

For example:

Type      Server                Local
============================================
Active    $/Work/Main           C:\Code\Main
Cloaked   $/Work/Main/Packages

Solution 12 - Tfs

I had the same issue. /packages should work but didn't for me. packages*.* did work.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMattView Question on Stackoverflow
Solution 1 - TfsPharylonView Answer on Stackoverflow
Solution 2 - TfsRyan GatesView Answer on Stackoverflow
Solution 3 - TfsAdam StewartView Answer on Stackoverflow
Solution 4 - TfsTerje SandstrømView Answer on Stackoverflow
Solution 5 - TfsDaniel MannView Answer on Stackoverflow
Solution 6 - TfsRiegardt SteynView Answer on Stackoverflow
Solution 7 - TfsJust TFSView Answer on Stackoverflow
Solution 8 - TfsMrHinsh - Martin HinshelwoodView Answer on Stackoverflow
Solution 9 - TfsDavid WiltonView Answer on Stackoverflow
Solution 10 - TfsredcalxView Answer on Stackoverflow
Solution 11 - TfsDaveShawView Answer on Stackoverflow
Solution 12 - Tfscoding4funView Answer on Stackoverflow