How to Check-In, Check-Out silently using commands in TFS?



Majority of the developers uses source control server as their project’s repository. SVN and TFS (Team Foundation Server) are one of them. If you are one of the user, you are already familiar with the Check-In and Check-Out process that we do from Team Explorer.

 

In some case, you may need to do the same from command prompt. Today, this post will cover how to Check-Out and Check-In files/folders from command prompts.

 

Visual Studio comes up with a command file named “TF.exe” which resides in the common IDE folder of the Visual Studio installation directory. If you want to check-out and check-in files or folders silently from the Team Foundation Server using commands, you have to be familiar with this TF.exe file.

 

Source Control ServerIf you are using Visual Studio 2008, you will find it under:

"X:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\TF.exe"

 

If you are using Visual Studio 2010, you will find it under:

"X:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\TF.exe"

 

If you are using Visual Studio 2012, you will find it under:

"X:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\TF.exe"

 

 

Check-Out Files or Folders from Command Prompt

If you are looking for a way to silently check-out files or folders from command prompt (mostly we need this when writing a batch script), in the command prompt, enter the following command:

 

“C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\TF.exe” checkout “COMPLETE_TFS_PATH” /recursive

 

I assume here that, you are using Visual Studio 2012 (version 11.0) and the Visual Studio instance is installed under “C:\Program Files (x86)” directory. In case, it differs, provide the proper path as mentioned above.

 

Provide proper path for “COMPLETE_TFS_PATH”, which could be a branch, specific folder or a file e.g. “$/Kunal-Chowdhury” or “$/Kunal-Chowdhury/Blog” or “$/Kunal-Chowdhury/Blog/default.html”.

 

Check-In Files or Folders from Command Prompt

Similarly, if you are looking for a way to silently check-in files or folders from command prompt (mostly we need this when writing a batch script), enter the following command:

 

“C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\TF.exe” checkin “COMPLETE_TFS_PATH” /recursive

 

Again, I assume here that, you are using Visual Studio 2012 (version 11.0) and the Visual Studio instance is installed under “C:\Program Files (x86)” directory. In case, it differs, provide the proper path as mentioned above.

 

Don’t forget to change “COMPLETE_TFS_PATH”, which could be a branch, specific folder or a file e.g. “$/Kunal-Chowdhury” or “$/Kunal-Chowdhury/Blog” or “$/Kunal-Chowdhury/Blog/default.html”.

 

Get Files or Folders Recursively from Command Prompt

So, we learnt how to check-in or check-out files or folders to/from TFS. So, what about getting the latest version of the source code from Team Foundation Server? Yes, you can do that too from the command prompt and by using these commands, you can create different batch files and  process them silently in different need.

 

To get read only copies of files and folder from TFS recursively, enter the following command which will download them in the workspace folder:

 

“C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\TF.exe” get “COMPLETE_TFS_PATH” /recursive

 

Don’t forget to change “COMPLETE_TFS_PATH”, which could be a branch, specific folder or a file e.g. “$/Kunal-Chowdhury” or “$/Kunal-Chowdhury/Blog” or “$/Kunal-Chowdhury/Blog/default.html”.

 

End Note

I hope that this post will help you in case you want to do some batch processing with your source control system to retrieve, check-out, check-in stuffs silently. This is mainly important when you are building a pre-build event or post-build event in your Visual Studio project properties.

 

Want to learn about it? Ok, we will discuss it someday in another blog post. Till then, enjoy learning and follow my blog for various articles & tips. I am available on Twitter and Facebook. Why don’t you connect with me and say a “Hello”? Have a great day! Enjoy your coding stuffs.

10 comments

  1. Fantastic post. Thanks for sharing.

    ReplyDelete
    Replies
    1. Thanks a lot Somesh for reading the post.

      Delete
  2. Bidhu Bhushan MishraJune 21, 2013 at 12:54 AM

    What is github? I heard about it few weeks ago and it's similar to TFS. If that is available for free, why should I go for TFS by paying dollars to Microsoft? Can you tell me the reason why TFS is preferred in companies?

    - Bidhu

    ReplyDelete
    Replies
    1. @Bidhu,

      GitHub is also similar to TFS but hosted in cloud. It is free only for Open Source projects where people can contribute. But if you want GitHub for your private/business code repository, you have to purchase different plans. Complete plan details available here: https://github.com/plans.

      I hope, this will clear all your doubts.

      Regards,
      Kunal

      Delete
  3. Very good post. I was not aware of this earlier. I will try it today.

    ReplyDelete
  4. Hello,

    Thank you for the useful post. How do I add in the post build command if during check in codes, it requires check-in notes for code reviewer. This is the error message that I got: TF10117: The following check-in note does not pass check-in requirement:
    Code Reviewer: A value must be specified for the check-in note.

    How do I check in silently by also check in the code reviewer name as well?

    Please enlighten me. I appreciate it. Thanks!

    ReplyDelete
  5. Hi Fazzy,

    That's a manual process. You can not do a silent check-in when when review comment and reviewer name is mandatory. This is to make sure that, you are reviewing the code properly before check-in.

    Regards,
    Kunal

    ReplyDelete
  6. Nice post Kunal. I'm trying to checkout a file. I am trying below pattern:
    “C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\TF.exe” checkout “COMPLETE_TFS_PATH” /recursive

    Question - How can I instruct tfs to use a specific workspace? Because above command leads to an exception message saying "Unable to determine the workspace".

    ReplyDelete


 
© 2008-2014 Kunal-Chowdhury.com | Designed by Kunal Chowdhury
Back to top