Share via


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="https://schemas.microsoft.com/developer/msbuild/2003">

 

   <Target Name="Dummy">

      <Exec

         WorkingDirectory="c:\"

         Command="dir"/>

   </Target>

</Project>

 

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="https://schemas.microsoft.com/developer/msbuild/2003">

 

   <PropertyGroup>

 

      <!-- operating folder -->

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

 

      <!-- Path to command line tool -->
<TfCommand>&quot;$(_GiveYourPathToTool_)\tf.exe&quot;</TfCommand>

      <ServerName>https://MyDummyVSTSServer:8080</ServerName>

      <WorkspaceName>DummyWorkspace</WorkspaceName>

</PropertyGroup>

    

   

   <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" />

 

   </Target>

 

</Project>

Comments

  • Anonymous
    January 11, 2006
    Manish,
    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?

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

  • Anonymous
    January 15, 2006
    Pablo,

    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.

    Manish

  • Anonymous
    October 31, 2006
    PingBack from http://www.dioramadesign.net/blog/creating-site-tfs-and-msbuild/

  • Anonymous
    October 05, 2007
    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.

  • Anonymous
    November 20, 2007
    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. Thanks

  • Anonymous
    December 17, 2007
    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 -Jaydev