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
<PropertyGroup>
<!-- operating folder -->
<SolutionRoot>c:\temp</SolutionRoot> <WorkingDirectories>$(SolutionRoot)\..\Reusable Code</WorkingDirectories>
<!-- Path to command line tool --> <TfCommand>"$(_GiveYourPathToTool_)\tf.exe"</TfCommand>
<ServerName>http://MyDummyVSTSServer:8080</ServerName>
<WorkspaceName>DummyWorkspace</WorkspaceName>
</PropertyGroup>
<! -- 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) "$/Reusable Code" "$(SolutionRoot)\..\Reusable Code "" WorkingDirectory="$(WorkingDirectory)" ContinueOnError="false"/>
<! -- Sync files on the local disk -->
<Exec Command="$(TfCommand) get "$/Reusable Code" /recursive /version:T /force" WorkingDirectory="$(WorkingDirectory)" ContinueOnError="false" />
<! --Apply Label on workspace --> <Exec Command="$(TfCommand) label /server:$(ServerName) $(_GiveYourLabelName_) "$/Reusable Code" /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 "$/Reusable Code/dummyfile.txt"" WorkingDirectory="$(WorkSpaceName)" ContinueOnError="false"/>
<!-- Delete dummy workspace --> <Exec Command="$(TfCommand) workspace /delete $(WorkSpaceName) /server:$(ServerName) /noprompt" WorkingDirectory="$(WorkingDirectory)" ContinueOnError="false" />