91

We have multiple config files (app.DEV.config, app.TEST.config, etc) and a pre-build event that copies the correct config file to app.config. Obviously the configuration specific files are in source control --- but at the moment so is App.Config, and that shouldn't be.

How can I mark that one file as excluded from source control, but obviously not from the project.

I'm using VS 2005, and 2005 Team Explorer.

SteveC
  • 15,808
  • 23
  • 102
  • 173
Ralph Shillington
  • 20,718
  • 23
  • 91
  • 154
  • http://stackoverflow.com/q/9741975/147211 – KMoraz Mar 16 '12 at 19:04
  • 1
    possible duplicate of [How to ignore files/directories in tfs?](http://stackoverflow.com/questions/922798/how-to-ignore-files-directories-in-tfs) – JohnC May 07 '15 at 18:55

12 Answers12

97

It's easy in TFS2012, create a .tfignore file

http://msdn.microsoft.com/en-us/library/tfs/ms245454%28v=vs.110%29.aspx#tfignore

######################################
# 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

# EDIT https://msdn.microsoft.com/en-us/library/ms245454(v=vs.110).aspx#tfignore
# A filespec is recursive unless prefixed by the \ character.
inoabrian
  • 3,762
  • 1
  • 19
  • 27
artfulhacker
  • 4,823
  • 1
  • 37
  • 31
  • 1
    how would you do a recursive ignore packages folder, but include packages/repositories.config? – Maslow Feb 05 '14 at 18:31
  • @Maslow, if you got it, feel free to edit my answer. seems like a pretty common setting and we should put it in the example – artfulhacker Feb 07 '14 at 19:20
  • does a .tfignore file in the root of the project collection automatically apply down the hierarchy even if they don't have that folder mapped/downloaded? – Maslow Apr 20 '14 at 18:03
  • 2
    This is only supported with Local workspaces. http://msdn.microsoft.com/library/vstudio/ms245454%28v=vs.110%29.aspx#tfignore – Sumo Dec 16 '14 at 15:11
  • `.tfignore` file will not ignore the file has added into Source Control. – Mr. Squirrel.Downy Feb 02 '23 at 03:55
49

Select the App.config file in Solution Explorer, and choose File -> Source Control -> Exclude App.config from Source Control.

PjL
  • 982
  • 7
  • 10
  • 1
    exactly what i needed to not store my minified files. – Valamas Aug 10 '11 at 22:48
  • 14
    It bugs me that this option isn't listed in the ordinary Context Menu – Eric Herlitz Apr 25 '12 at 10:50
  • 6
    I don't have that option. :'-( – Jan Aagaard Jun 20 '13 at 07:42
  • This option isn't present in Visual Studio 2012 Professional (unless I have misconfigured something, I guess) – Rumi P. Oct 30 '13 at 12:59
  • 2
    It isn't present in Visual Studio 2013 Ultimate either :( – Ytrog Jun 05 '14 at 09:22
  • What's the difference between excluding, ignoring, and cloaking? – Joshua Frank Sep 19 '14 at 14:14
  • 7
    It is present (under File > Source Control > Advanced > Exclude App.config from Source Control) in my Visual Studio Premium 2013 (Version 12.0.3023.00 Update 3). – Martin Bäckström Nov 05 '14 at 07:58
  • @JoshuaFrank I'm guession that Excluding will remove the server version (like a delete + ignore) and Ignoring will stop TFS from registering changes to your local copy. No idea about cloaking. – Sellorio Nov 12 '14 at 22:43
  • Thanks @MartinBäckström, that option shows for me in Visual Studio 2012 Version 11.0.61030.00 Update 4. It's a shame that option isn't in the menu when you right click the file itself. – jtate Dec 12 '14 at 16:21
  • This seems to actually do no good. I have a file created by the pre-build step, was checked in, now shows excluded from source control (red circle with horz bar), but when I build, the file gets checked out anyway. – Dave Apr 22 '15 at 21:59
39

There is a checkin policy (Forbidden Patterns Policy) in the MS Power Tools which lets you screen filenames against a regular expression. See: Microsoft Team Foundation Server Power Tools

While checkin policies are not completely foolproof, they are the closest thing TFS has to enforcing user-defined rules like what you're looking for.

(And as the others have said, you can also cloak a file or folder, which means it stays in Source Control and is visible to everyone else on the team, but it's not copied to your PC until you decide to uncloak it; or you can delete the file, which means it gets deleted from everybody's PCs when they get latest - but neither of these options will prevent such files being added to source control in the first place)

Zverev Evgeniy
  • 3,643
  • 25
  • 42
Jason Williams
  • 56,972
  • 11
  • 108
  • 137
  • 1
    The team-project-wide exclusion feature you're describing doesn't exist in TFS, unfortunately. (unless it's in a more recent build of 2010 than mine) The "Source Control File Types" dialog controls which file types are non-mergeable, i.e. locked exclusively. – Richard Berg Sep 02 '09 at 21:11
  • I have VSTS2005/2008 at work, but am writing this at home, so my answer was from my rather poor memory - sorry! Just realised that what you need is the TFS Power Tools "forbidden patterns" check in policy. This allows you to match filenames using a regex and block checkins of unwanted filenames: http://msdn.microsoft.com/en-us/teamsystem/bb980963.aspx#checkin – Jason Williams Sep 02 '09 at 21:43
  • Good call, I'd forgotten about that policy. I'll edit your post to give it visibility. – Richard Berg Sep 03 '09 at 04:03
  • How can I uncloak one branch ??? I have hidden a branch by mistake and I can't uncloak it VS2012 – rolivares Jul 27 '16 at 02:39
24

There is an option that is hard to find:

1. Select the file or multiple files in Solution Explorer

2. Go to File -> Source Control -> Advanced

Path To Exclude

and here it is

Here is the Exclude

Keep in mind: If you right click a file in Solution Explorer you only find "the most important options" not all :)

Felix Keil
  • 2,344
  • 1
  • 25
  • 27
13

If all you want is to have a file in the project but not under source control with TFS, just go into SourceControl, delete the said file, and undo your checkout of the project file (it will attempt to remove the file from the project as well). Then check-in your delete of the file you are excluding. In the solution explorer you should see that there is no source control icon next to the file you're excluding. The project file should list a file there, but that file should now no longer be under source control.

Keep in mind, any other person will now see a missing file in the project when they get latest.

Seth
  • 149
  • 3
7

TFS allows you to cloak at the folder/file level. When something is cloaked, TFS won't attempt to sync it (much like a svn:ignore).

When setting up your workspace, cloak anything you want TFS to ignore. A more detailed how-to is here.

joshua.ewer
  • 3,944
  • 3
  • 25
  • 35
  • if only there were a way to cloak the folder for all work-spaces... don't see any equivalent setting under security. – felickz Mar 26 '13 at 14:28
  • You can't cloak at the file level; only folder. – dudeNumber4 May 12 '14 at 15:00
  • @dudeNumber4 I believe this feature was disabled in later versions of TFS, well after the initial answer was written. You could try this hack though: http://social.msdn.microsoft.com/Forums/vstudio/en-US/aef6aeba-9cc5-4be5-9a5e-af084eead4b5/is-it-possible-to-cloak-individual-files-in-tfs-2010?forum=tfsgeneral – joshua.ewer May 15 '14 at 20:43
5

This worked for me:

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.

Source: =">How can I exclude a specific files from TFS source control

David
  • 72,686
  • 18
  • 132
  • 173
Huilaaja
  • 51
  • 1
  • 2
2

Visual Studio 2013 (and 2012)

This feature is available by selecting the file(s) and going to:

File > Source Control > Advanced > Exclude ... from Source Control
Evan Mulawski
  • 54,662
  • 15
  • 117
  • 144
2

This question was asked a while ago but it pertains to the same type of issue I was having.

The Problem:

  • We want to check in our code.
  • We then want build our project.
    • During our build we depend on Build Events to move files around so we have the proper files in place for the build process to complete.
  • When our Build Event tries to copy the files, we get Access Denied errors.

The Reason:

  • Team Foundation Server Visual Studio Plugin changes the Read Only attribute on our files to READONLY TRUE when we check in our files.

Build Event Example:

  • copy "$(TargetDir)SomeFile.ext" "$(ProjectDir)"

Above, we simply need to move a file from our Target Build Path (the bin\debug or bin\release folders) to our Project Folder. In my situation, this was so I could include project built files in my installer. My Installer wasn't grabbing them as part of the Project Output.

The Fix: (nearly kicked my self in the face when I figured this out)

New Build Event:

  • attrib -R "$(ProjectDir)SomeFile.ext"
  • copy "$(TargetDir)SomeFile.ext" "$(ProjectDir)"
  • attrib +R "$(ProjectDir)SomeFile.ext"

We're all having fun with Build Events right? Above I simply do 2 things, I remove the read only attribute, now the files not read only. Copy my file as I was originally wanting to. Then replace the Read Only Attribute (optional I guess) to keep Visual Studio and Team Foundations happy.

And yes... I'm still kicking myself in the face on this one.

Rob K.
  • 519
  • 6
  • 16
0

I have a similar issue, my App.config contained sensible data (e.g. username) that this data should not by sync with TFS.

The article Best practices for deploying passwords and other sensitive data to ASP.NET and Azure App Service describes an good approach to prevent this issue:

Use the "file" attribute of the "appSettings" element to reference an config file that is not added to source-control

thuld
  • 680
  • 3
  • 10
  • 29
0

If you have an older version than TFS2012 and thus can't create a .tfignore file or use the File > Source Control > Advanced > Exclude … option, you can try this:

  • Make a copy of the target file in Windows Explorer.
  • Undo Pending Changes (if any) on the target file in Team Explorer/Visual Studio.
  • Delete the target file in Windows Explorer.
  • Move the copy of the target file to the location of the deleted target file, and rename it so it has the same name as the deleted target file.

TFS now seems to ignore the changes in the target file. If you need to edit the file again, don't use Visual Studio, as TFS will then put the file back in the list of files with Pending Changes.

Protector one
  • 6,926
  • 5
  • 62
  • 86
0

You can just simply select the file from your Source Control Explorer and Right Click on it, and the select the "Rename" option from there, and you can add ".exclude" at the end of the file name.

And then do remember to check-in the file, and after that you can see that your file is excluded from Source Control.