我尝试通过使用TFS API的C#程序设置构建过程参数。此BuildDefinition是BuildDeployTest工作流程(稍微修改一下LabDefaultTemplate.11.xaml)。我可以通过以下代码更改所有实验室流程设置(实验室工作流程参数):
System.Collections.Generic.IDictionary<string, object> myDictionary = Microsoft.TeamFoundation.Build.Workflow.WorkflowHelpers.DeserializeProcessParameters(buildDefinition.ProcessParameters);
foreach (var Parameter in myDictionary)
{
if (Parameter.Key == "LabWorkflowParameters")
{
// copy the entry
Microsoft.TeamFoundation.Lab.Workflow.Activities.LabWorkflowDetails myCopy = Parameter.Value as Microsoft.TeamFoundation.Lab.Workflow.Activities.LabWorkflowDetails;
foreach(TestAgentListItem testAgent in listOfTestAgents)
{
if(testAgent.Checked == true)
{
myCopy.EnvironmentDetails.LabEnvironmentName = testAgent.TestAgentName;
myCopy.EnvironmentDetails.LabEnvironmentUri = new Uri(testAgent.LabEnvironmentUri);
break;
}
}
myDictionary[Parameter.Key] = myCopy;
}
break;
}
request.ProcessParameters = Microsoft.TeamFoundation.Build.Workflow.WorkflowHelpers.SerializeProcessParameters(myDictionary);
// trigger a new Build
buildServer.QueueBuild(request);
我有另一个名为“TestDirectory”的Build流程参数,它显示在Build process parameters - &gt;下面。 3.其他 - &gt; TestDirectory。我试图改变这个参数
myDictionary["TestDirectory"] = @"TestDir";
但它没有改变。
在PowerShell中,我只需输入
[Microsoft.TeamFoundation.Build.Client.IBuildDefinition] $BuildDef = $buildserver.GetBuildDefinition($project,$buildDefinition)
[Microsoft.TeamFoundation.Build.Client.IBuildRequest] $BuildReq = $BuildDef.CreateBuildRequest();
$processParameters = [Microsoft.TeamFoundation.Build.Workflow.WorkflowHelpers]::DeserializeProcessParameters($BuildReq.ProcessParameters)
$processParameters.TestDirectory = "TestDir"
但我怎么能用C#做到这一点?
此致
答案 0 :(得分:4)
如果您已经分配了价值,它将不会改变。
尝试以下:
string argumentName = "TestDirectory";
var process = Microsoft.TeamFoundation.Build.Workflow.WorkflowHelpers.DeserializeProcessParameters(BuildDefinition.ProcessParameters);
if (process.ContainsKey(argumentName))
{
process.Remove(argumentName);
process.Add(argumentName, attributeValue);
BuildDefinition.ProcessParameters = WorkflowHelpers.SerializeProcessParameters(process);
BuildDefinition.Save();
}