270

Is it possible to set up files/folders to ignore on a per-project basis in TFS source control?

For example, I've a website with an assets folder that I do not want to go in to source control. These assets are maintained by a separate system. Also, I don't want to put several gigabytes of assets into source control, but I need a couple of samples on my dev machine, but I don't want to check those in either.

If I'm working on this website while bound to source control and I refresh the tree, these files will automatically get added again

I want to prevent this from happening.

1
  • 1
    For local Workspaces you can use the .tfignore-Files like Richard Banks points out. For adjusting this file with Context-Menue in team-Explorerer, see my Answer. For Server-Workspaces I provided a link in the comments.
    – gReX
    Jul 20, 2015 at 9:50

6 Answers 6

184

If you're using local workspaces (TFS 2012+) you can now use the .tfignore file to exclude local folders and files from being checked in.

If you add that file to source control you can ensure others on your team share the same exclusion settings.

Full details on MSDN - http://msdn.microsoft.com/en-us/library/ms245454.aspx#tfignore

For the lazy:

You can configure which kinds of files are ignored by placing a text file called .tfignore in the folder where you want rules to apply. The effects of the .tfignore file are recursive. However, you can create .tfignore files in sub-folders to override the effects of a .tfignore file in a parent folder.

The following rules apply to a .tfignore file:

  • # begins a comment line
  • The * and ? wildcards are supported.
  • A filespec is recursive unless prefixed by the \ character.
  • ! negates a filespec (files that match the pattern are not ignored)

Example file:

# Ignore .cpp files in the ProjA sub-folder and all its subfolders
ProjA\*.cpp
# 
# Ignore .txt files in this folder 
\*.txt
#
# Ignore .xml files in this folder and all its sub-folders
*.xml
#
# Ignore all files in the Temp sub-folder
\Temp
#
# Do not ignore .dll files in this folder nor in any of its sub-folders
!*.dll
10
  • 45
    i have tried doing that. the only thing getting ignored is the contents of the .tfignore file :( Dec 21, 2014 at 7:03
  • 2
    I added this at the Solution level and it did not work...do I have to drill down to the actual location of the file? Based on your answer, it doesn't seem like I'd need to...and it's .tfignore.txt right?
    – Serj Sagan
    Feb 9, 2015 at 18:16
  • 1
    @SerjSagan The file is just .tfignore, no extension. Feb 10, 2015 at 10:57
  • 19
    @SerjSagan my computer didn't allow me to create .tfignore so i created .tfignore. and it removed the last dot on its own..
    – Peter
    Mar 21, 2015 at 13:42
  • 7
    The problem is that it ignores only resources, which were 1) explicitly deleted in Source Control Explorer window before check-in and 2) explicitly excluded in the Pending Changes window. For example, if you are going to use it to ignore packages folder and rely on NuGet Package Restore, you will need to 1) delete packages folder in Source Control Explorer and then 2) exclude it in Pending Changes window after the NuGet Package Restore process. Otherwise it will still check-in the packages folder.
    – Deilan
    May 22, 2015 at 13:32
103

For VS2015 and VS2017

Works with TFS (on-prem) or VSO (Visual Studio Online - the Azure-hosted offering)

The NuGet documentation provides instructions on how to accomplish this and I just followed them successfully for Visual Studio 2015 & Visual Studio 2017 against VSTS (Azure-hosted TFS). Everything is fully updated as of Nov 2016 Aug 2018.

I recommend you follow NuGet's instructions but just to recap what I did:

  1. Make sure your packages folder is not committed to TFS. If it is, get it out of there.
  2. Everything else we create below goes into the same folder that your .sln file exists in unless otherwise specified (NuGet's instructions aren't completely clear on this).
  3. Create a .nuget folder. You can use Windows Explorer to name it .nuget. for it to successfully save as .nuget (it automatically removes the last period) but directly trying to name it .nuget may not work (you may get an error or it may change the name, depending on your version of Windows). Or name the directory nuget, and open the parent directory in command line prompt. type. ren nuget .nuget
  4. Inside of that folder, create a NuGet.config file and add the following contents and save it:

NuGet.config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <solution>
        <add key="disableSourceControlIntegration" value="true" />
    </solution>
</configuration>
  1. Go back in your .sln's folder and create a new text file and name it .tfignore (if using Windows Explorer, use the same trick as above and name it .tfignore.)
  2. Put the following content into that file:

.tfignore:

# Ignore the NuGet packages folder in the root of the repository.
# If needed, prefix 'packages' with additional folder names if it's 
# not in the same folder as .tfignore.
packages

# include package target files which may be required for msbuild,
# again prefixing the folder name as needed.
!packages/*.targets
  1. Save all of this, commit it to TFS, then close & re-open Visual Studio and the Team Explorer should no longer identify the packages folder as a pending check-in.
  2. Copy/pasted via Windows Explorer the .tfignore file and .nuget folder to all of my various solutions and committed them and I no longer have the packages folder trying to sneak into my source control repo!

Further Customization

While not mine, I have found this .tfignore template by sirkirby to be handy. The example in my answer covers the Nuget packages folder but this template includes some other things as well as provides additional examples that can be useful if you wish to customize this further.

5
  • 1
    Followed this on VS 2017 - TFS 2015. Worked like a charm. All of my Nuget packages no longer showed up as pending changes. Nov 1, 2017 at 18:54
  • I just had to open the detected changes and add the newly created files to the pending changes by hand. Except that everything worked fine.
    – Machado
    Mar 13, 2018 at 14:17
  • This didn't work for me. VS 2017 - TFS 2015. I cannot check anything in. When I try I get the following error: " D:\Src\MiniCoreWebAPI\packages\Microsoft.IdentityModel.Protocols.5.2.1\lib\net451\Microsoft.IdentityModel.Protocols.dll: Could not find a part of the path"
    – Rod
    Jul 17, 2018 at 20:17
  • 1
    I didn't have my packages folder checked in, but it was already detected as a pending change. After applying these instructions, I had to "Undo Pending Changes" on the packages folder, then everything was fine when I rebuilt and NuGet restored the packages.
    – CodeHxr
    Aug 30, 2019 at 15:19
  • 1
    Looks like your answer has hardly anything to do with the question. The question was not about NuGet, but how to exclude a file from TFS. Sep 3, 2022 at 7:29
74

It does seem a little cumbersome to ignore files (and folders) in Team Foundation Server. I've found a couple ways to do this (using TFS / Team Explorer / Visual Studio 2008). These methods work with the web site ASP project type, too.

One way is to add a new or existing item to a project (e.g. right click on project, Add Existing Item or drag and drop from Windows explorer into the solution explorer), let TFS process the file(s) or folder, then undo pending changes on the item(s). TFS will unmark them as having a pending add change, and the files will sit quietly in the project and stay out of TFS.

Another way is with the Add Items to Folder command of Source Control Explorer. This launches a small wizard, and on one of the steps you can select items to exclude (although, I think you have to add at least one item to TFS with this method for the wizard to let you continue).

You can even add a forbidden patterns check-in policy (under Team -> Team Project Settings -> Source Control... -> Check-in Policy) to disallow other people on the team from mistakenly checking in certain assets.

6
  • 7
    I didn't have a forbidden patterns policy. Answer to a related question reveals where to get it. It is apparently part of the TFS Power Tools. Dec 13, 2011 at 19:33
  • 1
    I am facing similar problem, can you provide more detail on a particular folder to be not checkin using Check-in Policy Mar 17, 2012 at 9:21
  • Whoops - you're right, Leif. It is part of the TFS Power Tools. Mar 23, 2012 at 20:31
  • Imran, unfortunately I switched jobs, and no longer use TFS and don't have access to my past projects, so I'm not sure about the syntax for the forbidden patterns check-in policy syntax. Maybe this questions helps? stackoverflow.com/questions/2741412/… Mar 23, 2012 at 20:34
  • TFS 2010 After you choose files to include, you can exclude from that list. Can't touch existing files...
    – JNF
    May 13, 2013 at 6:37
49

For TFS 2013:

Start in VisualStudio-Team Explorer, in the PendingChanges Dialog undo the Changes whith the state [add], which should be ignored.

Visual Studio will detect the Add(s) again. Click On "Detected: x add(s)"-in Excluded Changes

In the opened "Promote Cadidate Changes"-Dialog You can easy exclude Files and Folders with the Contextmenu. Options are:

  • Ignore this item
  • Ignore by extension
  • Ignore by file name
  • Ignore by ffolder (yes ffolder, TFS 2013 Update 4/Visual Studio 2013 Premium Update 4)

Don't forget to Check In the changed .tfignore-File.

For VS 2015/2017:

The same procedure: In the "Excluded Changes Tab" in TeamExplorer\Pending Changes click on Detected: xxx add(s)

The Excluded Changes Tab in TeamExplorer\Pending Changes

The "Promote Candidate Changes" Dialog opens, and on the entries you can Right-Click for the Contextmenu. Typo is fixed now :-)

5
  • Can't seem to find that option. I'm on VS 2015 RC. Jul 14, 2015 at 22:15
  • this will only work if you're working with a local workspace, as described in detail, here: msdn.microsoft.com/library/vstudio/…
    – stvn
    Jul 15, 2015 at 12:56
  • @Shimmy: The procedure in VS 2015 RC is the same, with still the same typo. See my updated Answer. But as stvn points out .tfignore only works with local workspaces. For server-workspaces you have to undo the Include in the Pending Checkins, see answer here: stackoverflow.com/questions/21887308/…
    – gReX
    Jul 16, 2015 at 9:05
  • @Shimmy: Are you connected to TFS-Server 2015? Ensure, that you start with Team Explorer in VS
    – gReX
    Jul 18, 2015 at 11:52
  • @qw1564 I'm quite sure, when the question was asked first, it wasn't possible the gui-way. But now, this is the answer I would choose. Thanks for the credits!
    – gReX
    Dec 19, 2015 at 18:53
5

I found the perfect way to Ignore files in TFS like SVN does.
First of all, select the file that you want to ignore (e.g. the Web.config).
Now go to the menu tab and select:

File Source control > Advanced > Exclude web.config from source control

... and boom; your file is permanently excluded from source control.

3
  • 1
    this is working for me on TFS 2010 for code generated files. THX!
    – BozoJoe
    May 18, 2016 at 22:20
  • 1
    This actually works, the .tfignore doesn't work for me. Thanks a ton
    – EpicKip
    Jan 16, 2018 at 13:17
  • 2
    I don't have this option in VS 2018
    – Adam
    May 8, 2019 at 9:18
4

I'm going to assume you are using Web Site Projects. These automatically crawl their project directory and throw everything into source control. There's no way to stop them.

However, don't despair. Web Application Projects don't exhibit this strange and rather unexpected (imho: moronic) behavior. WAP is an addon on for VS2005 and comes direct with VS2008.

As an alternative to changing your projects to WAP, you might consider moving the Assets folder out of Source control and into a TFS Document Library. Only do this IF the project itself doesn't directly use the assets files.

1
  • yes, your assumption is correct. I thought that would be the case, just wanted to be doubly sure I didn't miss anything.
    – David
    May 29, 2009 at 2:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.