MSbuild tasks to integrate/customize Team Foundation Version Control functionality with Team Build


You can use MSbuild exec task to execute any system command. The task also gives you option to specify the working folder from where to execute the command. This is useful for the scenarios where you want to run a tool from specific location. Do note that this task creates a new process and there are performance implications associated with the use.


Simple example on how to run any external command :-


<Project xmlns=""> 

   <Target Name="Dummy">







Simple example on

  1. How to create new workspace?

  2. How to modify the folder mappings of the workspace?

  3. How to get files from the repository?

  4. How to apply label to files in the workspace?

  5. How to checkout specific file? 

  6. How to delete the workspace?  

<Project xmlns="">




      <!-- operating folder -->

      <WorkingDirectories>$(SolutionRoot)\..\Reusable Code</WorkingDirectories>


      <!-- Path to command line tool -->






   <Target Name="Dummy">


      <! --  Create dummy workspace --> 
      <Exec Command="$(TfCommand) workspace /new $(WorkSpaceName) /server:$(ServerName) /noprompt" WorkingDirectory="$(WorkingDirectory)" ContinueOnError="false"/>


      <! -- Add mappings to the workspace --> 
      <Exec Command="$(TfCommand) workfold /map /workspace:$(WorkSpaceName) /server: $(ServerName)  &quot;$/Reusable Code&quot; &quot;$(SolutionRoot)\..\Reusable Code &quot;" WorkingDirectory="$(WorkingDirectory)" ContinueOnError="false"/>


     <! -- Sync files on the local disk -->

     <Exec Command="$(TfCommand) get &quot;$/Reusable Code&quot; /recursive /version:T /force" WorkingDirectory="$(WorkingDirectory)" ContinueOnError="false" />


     <! --Apply Label on workspace --> 
     <Exec Command="$(TfCommand) label /server:$(ServerName) $(_GiveYourLabelName_) &quot;$/Reusable Code&quot; /version:W$(WorkSpaceName) /recursive" WorkingDirectory="$(WorkingDirectory)" ContinueOnError="false"/>


     <!— Checkout the file $/Reusable Code/dummyfile.txt -->

     <!— Note that you can also specify the relative (w.r.t workingdirectory) local path of the file -->
     <Exec Command="$(TfCommand) edit &quot;$/Reusable Code/dummyfile.txt&quot;" WorkingDirectory="$(WorkSpaceName)" ContinueOnError="false"/>


      <!-- Delete dummy workspace --> 
      <Exec Command="$(TfCommand) workspace /delete $(WorkSpaceName) /server:$(ServerName) /noprompt" WorkingDirectory="$(WorkingDirectory)" ContinueOnError="false" />







Comments (7)

  1. Pablo says:


    Eventhough I’m using force and deleting the workspace again, I get "All files are up to date" when I run the script. Any thoughts?

  2. Pablo says:

    $/Reusable Code is an actual Project, I thought it was a directory. Useful post, thanks!

  3. ManishAgarwal says:


    It looks like there is no change in the version of files in your workspace. It happens sometimes when the tf.exe call fails to update the cache on your local machine.


  4. Frank says:

    Isn’t there a handy-dandy MSBuild task that provides integration with team foundation server?

    That ability is pretty foundational to any automated build process.

  5. Rahul says:

    Hi Manish,

    I tried running the script and get "All files are up to date". I dont think I have a cache problem as i tried doing in a freshly built machine which does not have any workspaces.

    Your help is appreciated.


  6. says:

    Hi Manish,

    I am trying to run a batch file, using the

    <Exec command = "c:run.bat" /> in TFSBuild.proj file

    But when building, its simply skipping and going further, please help me on this


Skip to main content