Hi all, one in a while we need to do some changes within our TFS Build process template, and a easy way to do it is using powershell in pre or post build command.
I will add a sample code to find the current workspace and then you can program what you need from this point on.
Code:
# load the needed client dll’s
[void][System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.TeamFoundation.VersionControl.Client”)
#here I’m considering that your workspace is one folder up
$rootBuildPath = (get-item $PSScriptRoot ).parent.FullName
#here I get the workspaces set for that local folder
$workspaceInfos = [Microsoft.TeamFoundation.VersionControl.Client.Workstation]::Current.GetLocalWorkspaceInfoRecursively($rootBuildPath)
#here I can get the tfs collection
$tfsCollection = [Microsoft.TeamFoundation.Client.TfsTeamProjectCollectionFactory]::GetTeamProjectCollection($workspaceInfos[0].ServerUri);
#then I can get the version control service
$vc = $tfsCollection.GetService([type] “Microsoft.TeamFoundation.VersionControl.Client.VersionControlServer”);
#and for example, download something
$fileXml = Join-Path -Path $rootBuildPath -ChildPath “file.xml”
$itemToDownload = $vc.GetItem(“$/teamProjectName/file.xml”, [Microsoft.TeamFoundation.VersionControl.Client.VersionSpec]::Latest);
$itemToDownload.DownloadFile($fileXml)
It works for all xaml builds and also for the new build system.