Build Task Help
I'm trying to execute a custom task from msbuildto branch a particular label of code to a different folder (development to staging) in source control, check that in and then perform the build. The dll I created to perform the branch works fine when called from my local machine but not when called from an msbuild task. Is there a way to manipulate source control using a task in msbuild?
I created a task assembly, which performs the branch operation, to call from msbuild....the code is below:
using
System;using Microsoft.Build.Framework;
using
Microsoft.Build.Utilities;using
Microsoft.TeamFoundation.Build.Client;using
Microsoft.TeamFoundation.Build;using
Microsoft.TeamFoundation.VersionControl.Client;namespace
BranchModule{
publicclassBranch :Task{
publicoverridebool Execute(){
String tfsName ="http://trafvsts:8080";Microsoft.TeamFoundation.Client.
TeamFoundationServer tfs = Microsoft.TeamFoundation.Client.TeamFoundationServerFactory.GetServer(tfsName);VersionControlServer vcs = (VersionControlServer)tfs.GetService(typeof(VersionControlServer));// Create a workspace.Workspace oWorkspace = vcs.GetWorkspace("Local Machine","vetric");// Delete all of the items in the destination folder.oWorkspace.PendDelete(mDestPath);
CheckInChanges(oWorkspace,
"Delete Previous Build");//Create the Version Label Spec from label nameMicrosoft.TeamFoundation.VersionControl.Client.
LabelVersionSpec lvs =newLabelVersionSpec(mLabelName, mScope);// Branch all of the items from source project.int iCount = oWorkspace.PendBranch(mSourcePath, mDestPath, lvs,LockLevel.None,true);if (iCount <= 0){
returnfalse; }else{
CheckInChanges(oWorkspace,
"Check-in Branch");returntrue;}
}
}
privatestring mSourcePath, mDestPath;privatestring mLabelName, mScope;publicstring SourcePath{
get {return mSourcePath; }set { mSourcePath =value; }}
publicstring DestinationPath{
get {return mDestPath; }set { mDestPath =value; }}
publicstring LabelName{
get {return mLabelName; }set { mLabelName =value; }}
publicstring Scope{
get {return mScope; }set { mScope =value; }}
}
__
I'm calling this code from the TFSBuild.proj with the code below:
<
UsingTaskTaskName="BranchModule.Branch"AssemblyFile="BranchModule.dll" /><
TargetName ="BranchProjectCode"><
BranchSourcePath="$/Development/Development/Test/Server"DestinationPath="$/Development/Staging/Test/Server"LabelName="IC-9 Dev.Test.Server"Scope="$/Development"/></
Target>I get the following errors:
Build FAILED.
c:\builds\Development\Staging.Test.Server\BuildType\TFSBuild.proj(184,5): error MSB4018: The "Branch" task failed unexpectedly.
c:\builds\Development\Staging.Test.Server\BuildType\TFSBuild.proj(184,5): error MSB4018: System.NotSupportedException: A local workspace is required. Workspace Local Machine;vetric does not reside on this computer.
c:\builds\Development\Staging.Test.Server\BuildType\TFSBuild.proj(184,5): error MSB4018: at Microsoft.TeamFoundation.VersionControl.Client.Workspace.RequireLocal()
c:\builds\Development\Staging.Test.Server\BuildType\TFSBuild.proj(184,5): error MSB4018: at Microsoft.TeamFoundation.VersionControl.Client.Workspace.PendDelete(String path)
c:\builds\Development\Staging.Test.Server\BuildType\TFSBuild.proj(184,5): error MSB4018: at BranchModule.Branch.Execute()
c:\builds\Development\Staging.Test.Server\BuildType\TFSBuild.proj(184,5): error MSB4018: at Microsoft.Build.BuildEngine.TaskEngine.ExecuteTask(ExecutionMode howToExecuteTask, Hashtable projectItemsAvailableToTask, BuildPropertyGroup projectPropertiesAvailableToTask, Boolean& taskClassWasFound)
It seems like the task is being executed against the VSTS server, which I do not have Visual Studio installed. Will this task work if I install Visual Studio and create a workspace or maybe there is a way to instruct msbuild to run the task locally or have I completely gone down the wrong path?

