Welcome to MSDN Blogs Sign in | Join | Help

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="http://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="http://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>http://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>

 

 

Published Tuesday, December 06, 2005 2:17 PM by ManishAgarwal

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

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

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?
Wednesday, January 11, 2006 9:31 PM by Pablo

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

$/Reusable Code is an actual Project, I thought it was a directory. Useful post, thanks!
Wednesday, January 11, 2006 10:17 PM by Pablo

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

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
Monday, January 16, 2006 1:06 AM by ManishAgarwal

# Creating Site: TFS and MSBuild at Dylan Marks&#8217; Weblog

Tuesday, October 31, 2006 4:59 PM by Creating Site: TFS and MSBuild at Dylan Marks’ Weblog

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

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.

Saturday, October 06, 2007 2:47 AM by Frank

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

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

Tuesday, November 20, 2007 1:48 PM by Rahul

# Placement of Exec tag in TFSBuild.proj

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

Monday, December 17, 2007 10:12 AM by jaydev

Leave a Comment

(required) 
required 
(required) 
 
Page view tracker