How can I exclude a specific file from TFS source control - tfs

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.

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.

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

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)

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
and here it is
Keep in mind:
If you right click a file in Solution Explorer you only find "the most important options" not all :)

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.

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.

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

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

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.

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

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.

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.

Related

How to prevent TFS from ignoring files

In a project I'm working on we check in Ruby with sass in order to compile scss files during the build. I switched to using a local workspace when updating gems so that changes are detected automatically. This works great except for the fact that files for new gems that reside in a bin folder are always ignored.
I have no existing tfignore files so I wonder is there some global ignore list that I could potentially edit or override.
I've tried adding a tfignore file at the root and even at the same level as the bin folder in an effort to force team explorer to stop ignoring those files but have had zero success thus far.
The content of the tfignore file is just one line:
!bin
How can I get team explorer to detect these changes automatically so I don't have to go through the extra step of finding and adding these files manually?
Bin and Obj folders are never shown in the project and adding files within those directories require some kind of manual step. If your goal by "not adding them manually" means you don't want to add them through "Source Control Explorer" but would just rather add them while working with a solution and project through "Solution Explorer", then you can click the "Show All Files" icon at the top of VS 2013/2012/2010.
This will then show you your potential bin/obj folders you may want to add files from:
Then you just right-click and include them. Once they're included, when you go to check them in, TFS knows you intend to add them to source control so it will show up in the Team Explorer pending changes window, if you are checking in from a higher-level in tree hierarchy. If you're not, then you can go to the "Excluded Changes" to find pending change you want to include in your final change.
If items are being excluded in anyway, try removing the .tfignore files and depending on your version of Visual Studio and settings, you may also be excluding your files through options such as this:
HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\10.0\TeamFoundation\SourceControl\AddOptions

What place should I put those source that's not defined in TFS2010

I have some source code and other artifacts such as images that are not created in Visual Studio 2010. I want to put them into TFS 2010 version control, how can I do this?
TFS does not care what the format of your files is; you can use TFS to store any type of file - whether it was created in Visual Studio or any other program. This is true of all TFS versions.
The comments already somewhat address how to add a file to Source Control using Source Control Explorer; Once you have a workspace mapping, copy files or folders into a mapped folder in your workspace, right-cick on the folder you added the file to in Source Contol Explorer and select the option to Add Items to Folder; This will launch a wizard that you can use to let TFS know that you want to add the selected file(s) or folder(s) to source control - it can be any file on your computer.
After the files are added, check-in yor changes by right-clicking on the file in Source Control Explorer or by using the Pending Changes window (View menu -> Other Windows -> Pending Changes). Almost every source control operation in TFS is a 2-phase commit that involves first letting TFS know what you want to do (like add or delete a file) and then actually committing that change with a check-in.
You can also perform these steps using TF.exe from the command line or the Shell Integration Feature that is installed seperately with Team Foundation Server Power Tools (TFPT). Please note that whilst you can list and view the contents of files in TFS using the Web Access user interface, you cannot check-in or check-out files using that interface. Also, you will not be able to perform any source control changes without Visual Studio or at least a free version of it, named Team Explorer.
The only qualities of files that matter to the behavior of TFS are if the file is a mergable file type or not and what the encoding of the file is; however, in most cases the default setings in TFS will be fine for you. Mergeable file types are files that TFS will enable merging for; Examples of mergable file types are text files; Non-mergeable file types are file types that you would not want to merge, like pictures or Microsoft Excel files. You can read more about Managing File Types on the Microsoft site.

How to see changes in local working copy in TFS?

I'm an experienced SVN user getting used to TFS at a new client site. The main problem I've had adjusting to the new tool is this - how can I get a listing of all files in my working copy that have changed from current/latest server revision, including added or deleted files?
Essentially, I'm looking for the TFS equivalent of an "svn diff". The "TF" command-line tool has a "diff" command which reports changed files but I can't find an option to report deleted or added files; this missing feature has resulted in a couple check-ins which (embarrassingly) broke the build.
Which version of TFS?
TFS2010 has a folder compare command, File > Source Control > Compare... (or in the Source Control Explorer, right-click on the project path you're interested in, and select Compare...).
Set up the Source path to be a folder on the server and the Target path to be a local folder in your workspace (or vice versa). Under View Options, select Show items that exist only in source path, Show items that exist only in target path and Show items that are different and click OK.
Is there any reason you can't use the Source Control Explorer?
If you right click on the folder, project or branch you can click Compare and you will see all files that have been deleted or added.
I usually do the following:
Open your Team Explorer tab in Visual Studio and click on Pending Changes.
There you will see your changed files.

Exclude from project, source control issue

I'm using team foundation server 2010 # work and home.
I want to exclude some element from the project build but still have them exist in Team Foundation Server 2010 source control. How do I achieve this?
Exclude From Project will delete the item.
Same problem here, only way to do this is manually edit project file :(
Please vote that this bug is important to fix
https://connect.microsoft.com/VisualStudio/feedback/details/573582/vs-2010-exclude-from-project-deleting-files-from-source-control
Workaround posted on Connect:
Open the csproj file in notepad and find the files that need to be
excluded and remove or comment the compile element for that file, and
any related designer and resx files.
Editing a project file and removing the references to the files you want to exclude would be the easiest solution.
Another solution would be to remove files from the project via UI, but only checkin changes in the project file and undo the delete operations.
In the future you can add files directly to the TFS folder in Team Explorer.
May I ask: why would you want to do that? As I commonly have a problem of files which are not bound to any project and have to be getted manually.
I work in a TFS environment, and if it were me? I'd just change the name of the file (instead of excluding it from the project), and check that in instead. Since your project is expecting that particular filename...it won't find it. We use this when we're developing prototypes or holding on to antiquated code for documentation purposes. Sorry VS is eating your stuff!
Kind Regards,
-sf
I think these steps should help you do what you are looking for.
To exclude an item from a deployment project:
In Solution Explorer, select the file you want to exclude.
On the Solution Explorer toolbar, select Properties.
In the Properties window, set the Exclude property to True.
And this page explains the actions for project files supported by VS 2010:
http://msdn.microsoft.com/en-us/library/0ebzhwsk.aspx
--- Edit ---
At work I tried 'Exclude From Project' in one of the files of a project we have in VS 2010, which is bound to a TFS 2010 server, and this action did not delete the item from TFS; the Source Control Explorer window shows the red delete mark next to the item, and the 'Pending Change' column says delete, but item is there. Right click the item in the Source Control Explorer window, one of the commands in the context menu that pops-up is 'Check In Pending changes' and another one is 'Shelve Pending changes'. Shelving enables you to set aside the pending changes.
The file is still in the local hard drive. If I do 'Include In Project' the item comes back to normal.

How to ignore files/directories in TFS for avoiding them to go to central source repository?

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.
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
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:
Make sure your packages folder is not committed to TFS. If it is, get it out of there.
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).
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
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>
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.)
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
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.
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.
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.
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 "Promote Candidate Changes" Dialog opens, and on the entries you can Right-Click for the Contextmenu. Typo is fixed now :-)
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.
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.

Resources