TFS(Team Foundation Server) Usage Guidelines

Setu Kumar Basak
8 min readMay 17, 2019

--

In today’s context, people mostly use Git as their version control system. But, while working in a software company, i have noticed, TFS(Team Foundation Server) is being widely used for version control.

Sometimes, people find difficult to familiarize with TFS and it’s functionalities. Today, i will go through some of the common functionalities that we do regularly in a software project.

Environment Setup:

  1. Microsoft Visual Studio 2012 to greater version
  2. Diff Merge: https://sourcegear.com/diffmerge/downloads.php

Note: In the following document, the guideline has been created using VS 2015 version.

Connect to a TFS Server Using The Following Link:

https://tfs.discountasp.net/kb/a1374/how-to-configure-visual-studio-2015-to-connect-to-team-foundation-server-2015.aspx

There are two sections will be displayed in Visual Studio 2015.

1. Solution Explorer

2. Team Explorer

Solution Explorer:

Solution explorer displays all the files stored locally. Open the .sln file from the local path of project repository. Thus, all the local files will be loaded in the solution explorer.

To View All Files from Solution Explorer:

  • Select the desired project repository from solution explorer.
  • Click on Show all files icon.
  • Observe, all the downloaded files of the local repository will be displayed.
Solution Explorer

Team Explorer:

Team explorer contains all the files that are stored already in server. After connecting to the server, user needs to navigate to the desired repository folder from Source Control Explorer Window.

Source Control Explorer Window can be displayed by selecting the following option:

Team Explorer

Source control explorer window in the left panel.

Source Control Explorer

Pending Changes:

Suppose, we have created a new file in our repository folder named test_tfs.py. There is written only one line of code i.e.

So, now if we click Pending Changes option from Team Explorer tab, we will see the following change.

As we have added only one new file so it is displayed Detected 1 add(s). After clicking detected option, we will be able to see the added file.

Pending Changes

Check In/Push New Item to Server:

To push this newly created file, we have to perform the following steps:

  1. Select and Promote the file.
  2. After promoting the file, it will be displayed in Included Changes section.
Check in

3. Then we need to provide a Check in comment in the text area. User can provide any text as necessary to identify his check-in.

4. Then, click Check In button.

5. Click yes from the confirmation prompt and the file will be pushed to the server.

6. A successful message with a changeset number will be displayed.

Now user can easily search his changeset using the generated changeset number. Thus, the new file is pushed to the server.

Note: Only the item under Included section will be checked in to the server.

Integrate DiffMerge to Compare and Merge Files:

Steps to Follow:

  1. Download and Install DiffMerge in the local development computer.
  2. Launch VS 2015 and connect to TFS server.
  3. Navigate to the following options:
    Tools->Options
  4. In the search box, type Source and press enter button.
  5. Select Team Foundation Server from the left panel.

6. Click on Configure User Tools button.

7. Click Add from the pop up window.

To Integrate Compare Files Provide:

  • Extension: .*
  • Operation: Compare
  • Command: Provide the local path of DiffMerge installed
    By default it is: C:\ProgramFiles\SourceGear\Common\DiffMerge\sgdm.exe
  • Arguments: /t1=%6 /t2=%7 %1 %2
  • Click Ok

8. Now, click the Add button again from Configure User Tools window

To Integrate Merge Files Provide:

  • Extension: .*
  • Operation: Merge
  • Command: Provide the local path of DffMerge installed
    By default it is:
    C:\Program Files\SourceGear\Common\DiffMerge\sgdm.exe
  • Arguments: /m /r=%4 /t1=%7 /t2=%8 /t3=%6 /c=%9 %2 %3 %1
  • Click Ok

9. Click ok in the remaining windows and restart VS 2015.

Now, we will make some changes in our previously created file named test_tfs.py and compare the local file with the server.

Compare Files:

Add the following line in test_tfs.py file: print(‘End of Code.’)

Now to compare this changed file with the server perform the following steps:

  • Click Pending Changes from Team Explorer.
  • Observe, test_tfs.py file is already displayed under Included section.
  • Right click on the file and click on Compare with Workspace Version.
  • DiffMerge will display the server file and the local file in two sections in a screen.
    Note: Click close icon if any other pop up window appears in the screen from DiffMerge.
  • In the DiffMerge screen, left side contains the contents of the file in server and the right side contains the contents of the file in local server.
  • After comparing, one can push or undo the changed file in the server.
  • One can also annotate or view history from this file.

Annotate:

Annotate works just like Blame of Git. One can see the changes made by each developer and also the date and changeset along with it.

Right click on the changed file and click Annotate.

View History:

By right clicking on the file and click View History option, one can easily see the number of commits made on this file. In our case, as we have made only one check in before, it is displaying only one commit.

Undo Changes:

Undo is like the feature of Discard in Git. By using Undo option, one can undo his latest actions performed in the files before checking in the server.

  • Right click on the desired file and click Undo option
  • Click Undo Changes and then Click on Yes to All.
  • Observe, changes made in the file has got disappeared.
  • Test_usage.py file is now same as the server file.

Exclude:

Exclude is similar unstaged file concept of Git. If user wants to checkin the file later, one can be able to do it by performing the following steps:

  • Right click on the file and click Exclude.
  • Changed file will be displayed under Excluded Changes section.

Note: This file will remain under Excluded Changes section until user includes it again.

Shelve:

This is a mechanism that is used when user has made some changes and wants to keep it in the server for future usage. Shelve works bit like Stash of Git. In git, we can stash the changes locally so that we can apply later on any branch. But, if we shelve in TFS, it will be saved in the server. We can not locally shelve in TFS.

Example: Suppose, user has added another line like below (print('Printing new string.')) in test_tfs.py file.

Steps:

  • Select the file that needs to be stored.
  • Click Shelve option from Team Explorer window.
  • Provide a Shelve message
  • By checking Preserve pending changes locally checkbox, user will be able to see the shelved file locally.
  • Click Shelve button.
  • Shelve successful message will be displayed.

Unchecking Preserve pending changes locally checkbox:

  • Provide the same steps and keep Preserve pending changes locally checkbox not selected.
  • Click Shelve button.
  • Observe, shelved file is not displayed in Team Explorer window.

View Shelveset:

  • Click Actions and click on Find Shelvesets.
  • Observe, shelvedset is displayed from the server.
  • By right clicking on the shelveset, one can use the shelved file by using Unshelve option and user can also delete the shelve from the server using Delete Shelveset option.

Merge Files:

Merge will be used when multiple user works in same file. In case of multiple users, one should always Get Latest version of the repository before check in code.

  • Open the desired folder from Source Control Window.
  • Right click on the folder in Source Control Window.
  • Click Get Latest Version.
  • Thus, the latest code will always be downloaded.
  • There can be merge conflict on the file and it will be shown like below
  1. We can take the Server version by clicking on the Take Server Version button

2. We can keep our local version by clicking on the Keep Local Version button

3. We can merge the changes by clicking on the Merge Changes in Merge Tool button. It will open the DiffMerge screen like below

Delete File from Both Server and Local Environment:

To delete a file, user have to perform the following steps:

  • Delete the file locally from the local drive.
  • Observe, the detected item in Team Explorer.
  • Deleted file will be displayed.
  • Promote the deleted file.
  • Deleted file will be displayed under Included Changes section.
  • Provide a commit message (Delete test file) and check in the file.
  • Checked in file will be deleted from the server and a change set will be generated.

Editing Check-In Message:

To edit checked in file message, we need to perform the following steps:

  • Right click on the repository folder from Source Control Window.
  • Click View History.
  • All the checked in changesets will be displayed.
  • Now select a changeset that user wants to edit.
  • From the right panel of Team Explorer Window, edit the message as required.
  • Click on Save and the checked in message will be edited.

That’s pretty much it for today.

--

--