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 name

Microsoft.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?

[10311 byte] By [Vetric] at [2008-2-15]
# 1

Vetric,

1) Is there a way to manipulate source control using a task in msbuild?

Please check the link http://blogs.msdn.com/manishagarwal/archive/2005/12/06/500440.aspx

2) Yes, build machine needs to have the team foundation client skew. Visual studio is not mangatory for the build machine.

3) Yes you need to have active workspace before checkin any file in the source control. Please create one workspace for your "Branch".

The link describe an easy way to do whatever you want. U can invoke any source control command using the msbuild exec command.

Hope it helps.

ManishAgarwal at 2007-9-9 > top of Msdn Tech,Visual Studio Team System,Team Foundation Server - Build Automation...

Visual Studio Team System

Site Classified