1

We just implemented TFS in our company and I accidentaly included the bin and obj folders. I would like to exclude them. I searched on Google and found basically 2 ways to accomplish this:

1) https://msdn.microsoft.com/en-us/library/66tw9ezk(v=vs.90).aspx

In Visual Studio, open Solution Explorer and select the file to exclude. On the File menu, click Source Control, then click Exclude from Source Control. When you are ready to place the file under source control, you can access the File menu and click Source Control, then uncheck Exclude from Source Control.

In my File>Source Control, I don't see exclude from source control there or under advanced.

2) How do I permanently exclude the bin and obj folders from TFS 2012 checkin?

I tried adding a .tfignore and I couldn't find the 'ignore by extension', 'ignore file', etc. in teh Promote Candidate Changes dialog box. As far as I understand this is only applies to a local workspace and not a server workspace.

We set up the solution to checkout a file whenever it's altered, so when someone builds the project he acquires an exclusive lock on the dlls and then nobody else is able to compile.

Community
  • 1
  • 1
Eitan
  • 1,434
  • 6
  • 21
  • 53
  • Why don't you just delete the bin and obj folders from TFS? When you add solutions to TFS, you should let Visual Studio do it for you by using the "Add solution to source control" command in the solution context menu. – OldFart Aug 12 '15 at 15:07
  • @OldFart It deletes it locally and for web projects the project won't compile when it's missing the bin folder i.e. it doesn't create it. – Eitan Aug 12 '15 at 15:08

2 Answers2

1

From my personal experience, the easiest way to achieve this is the following:

  1. View -> Team Explorer (Ctrl+\, Ctrl+M)
  2. Click on Pending Changes
  3. In your Included Changes list, right click on the desired folder.
  4. Click Exclude.

The excluded change should now appear in the Excluded Changes list below.

Mike Eason
  • 9,525
  • 2
  • 38
  • 63
  • Does that exclude the folder/file from TFS or from the current changeset? I tried that but when I compile it still locks the DLLs. – Eitan Aug 12 '15 at 14:24
  • I'm not too familiar with the terminology, but if you exclude any files/folders, it will not appear in the **Included Changes** list again (even after check in) unless you manually include it. – Mike Eason Aug 12 '15 at 14:25
  • If the whole team checks in their project and I add the obj and bin folders to the exlcuded changes list and I compile, the dlls are still locked (checked out) and nobody else can compile. – Eitan Aug 12 '15 at 14:27
  • Are your DLL's being compiled to a shared folder? – Mike Eason Aug 12 '15 at 14:31
  • It's being compiled to bin and obj folders that I accidentally included in TFS. I'm trying to exclude them from TFS so everyone has their own bin and obj folders. – Eitan Aug 12 '15 at 14:34
  • This is step 1 of the solution. Step two in my answer. – jessehouwing Aug 12 '15 at 14:55
1

After the steps Mike describes, you can go further and define an ignore rule. Undo the pending changes to the file you want to exclude and then click the "detected: 123" link that shows under "Excluded changes".

This open up a new window in which you can ignore these changes indefinitely. It does this by creating a .tfignore file and adding that to source control. The alternative to the UI is t create this file manually and checking it in. This should prevent Team Explorer from showing files that match the patterns in the ignore file.

Make sure that these files are deleted from source control, if they were checked in accidentally, you can destroy them to make sure they are truly gone. You'll need to do this from the commandline using tf destroy

The call to Destroy won't delete your local files when you use the remote itemspec to destroy them:

C:\>tf destroy /collection:http:
//jessehouwing:8080/tfs/DefaultCollection $/Scrum/test.txt.txt /noprompt
Destroyed: $/Scrum/test.txt.txt

C:\Program Files (x86)\Microsoft Visual Studio 14.0>dir "c:\Workspaces\Local\Scrum"
 Volume in drive C has no label.
 Volume Serial Number is 008A-AC5B

 Directory of c:\users\jhouw\Source\Workspaces\Local\Scrum

12-08-2015  20:12    <DIR>          .
12-08-2015  20:12    <DIR>          ..
12-08-2015  20:12                 0 test.txt.txt
               1 File(s)              0 bytes
               2 Dir(s)  297.229.512.704 bytes free

After performing a tf get /collection:http: //jessehouwing:8080/tfs/DefaultCollection $/Scrum /recursive it will indeed be deleted. This should not be an issue if the files in question are regenerated during the next build.

Promote Candidate Changes window where you can select Ignore

See also:

If you're using a server workspace, the only way I can think of is to set a Forbidden Path checkin policy for your source control repo. It's a part of the Team Foundation Server Power Tools; you'd need to install the version of the power tools that matches your Visual Studio version on all developers' machines.

Note: these use Regular Expressions, so you'll need to adjust your pattern to match ;).

enter image description here

Community
  • 1
  • 1
jessehouwing
  • 106,458
  • 22
  • 256
  • 341
  • ok I'll try that. Thanks! If it ignores the bin and dlls does that mean that it won't lock them as well? Will it remove them completely from the source control? – Eitan Aug 12 '15 at 15:21
  • ok I tried it and it works by giving me an error when trying to check in a pending item that matches the regex but the lock is still acquired on the existing bin files when altering it locally and it would be a pain to go through a list of 56 projects and manually exclude the bin and obj folders. It's crazy that there isn't an exclude from source control option! – Eitan Aug 12 '15 at 15:28
  • If you `tf destroy` those files once and for all your problems will go away. – jessehouwing Aug 12 '15 at 15:31
  • Won't that destroy the local versions when doing a get latest? It would also mean I'd have to set every person using the TFS as a TFS administrator :( – Eitan Aug 12 '15 at 15:34
  • If you do the tf-destory once, you can then set the Forbidden path policy from having them checked in again by accident. Yes, they'll get deleted after a get-latest. I don't see why this would be a problem. Rebuilding would recreate the files. – jessehouwing Aug 12 '15 at 18:29
  • when you checkin tfignore file, does TFS only ignore for your checkins or everyones? – Alex Gordon Jan 17 '17 at 01:43
  • Everyones, as soon as they retrieve that tfignore file to their workspace. – jessehouwing Jan 17 '17 at 01:57