Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get TFS to ignore my packages folder

Tags:

nuget

tfs

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?!

like image 648
Matt Avatar asked Jun 10 '14 14:06

Matt


People also ask

How do I add ignore files to TFS?

For TFS 2013: Start in VisualStudio-Team Explorer, in the PendingChanges Dialog undo the Changes whith the state [add], which should be ignored. In the opened "Promote Cadidate Changes"-Dialog You can easy exclude Files and Folders with the Contextmenu.

Should packages folder be in Source Control?

Should I check in the Packages folder in the Source Control to make them available for peers? The answer is "NO". You should not checkin packages folders since this will increase the size of the repository and it will become overhead when taking the latest (since the size of the packages folder is in the MBs).

Can I delete Visual Studio packages folder?

YES you can delete this directory, if you have uninstalled Visual Studio.

Can I delete .nuget Packages folder?

Yes, the . nuget folder is used as a cache for packages downloaded to speed up project restore and compilation. It can safely be removed.


2 Answers

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.

like image 51
Pharylon Avatar answered Sep 30 '22 12:09

Pharylon


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.

like image 39
Ryan Gates Avatar answered Sep 30 '22 11:09

Ryan Gates