ChatGPT解决这个技术问题 Extra ChatGPT

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

tfs

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.

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.

R
Richard Banks

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

i have tried doing that. the only thing getting ignored is the contents of the .tfignore file :(
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?
@SerjSagan The file is just .tfignore, no extension.
@SerjSagan my computer didn't allow me to create .tfignore so i created .tfignore. and it removed the last dot on its own..
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.
C
Community

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.


Followed this on VS 2017 - TFS 2015. Worked like a charm. All of my Nuget packages no longer showed up as pending changes.
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.
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"
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.
D
Derek Morrison

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.


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.
I am facing similar problem, can you provide more detail on a particular folder to be not checkin using Check-in Policy
Whoops - you're right, Leif. It is part of the TFS Power Tools.
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/…
TFS 2010 After you choose files to include, you can exclude from that list. Can't touch existing files...
C
Community

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)

https://i.stack.imgur.com/3R0WD.png

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


Can't seem to find that option. I'm on VS 2015 RC.
this will only work if you're working with a local workspace, as described in detail, here: msdn.microsoft.com/library/vstudio/…
@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/…
@Shimmy: Are you connected to TFS-Server 2015? Ensure, that you start with Team Explorer in VS
@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!
B
Bharat

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.


this is working for me on TFS 2010 for code generated files. THX!
This actually works, the .tfignore doesn't work for me. Thanks a ton
I don't have this option in VS 2018
N
NotMe

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.


yes, your assumption is correct. I thought that would be the case, just wanted to be doubly sure I didn't miss anything.

关注公众号,不定期副业成功案例分享
Follow WeChat

Success story sharing

Want to stay one step ahead of the latest teleworks?

Subscribe Now