如何使用 powershell 设置自定义 tfs 构建参数

How to set a custom tfs build parameter using powershell

我正在使用 powershell 来自动化 TFS 构建

    [Microsoft.TeamFoundation.Client.TfsTeamProjectCollection]$tfsc = [Microsoft.TeamFoundation.Client.TfsTeamProjectCollectionFactory]::GetTeamProjectCollection($TFSServer)
    $IBS = [Microsoft.TeamFoundation.Build.Client.IBuildServer]

    [Microsoft.TeamFoundation.Build.Client.IBuildServer] $buildserver = $tfsc.GetService($IBS)
    [Microsoft.TeamFoundation.Build.Client.IBuildDefinition] $BuildDef = $buildserver.GetBuildDefinition($Project,$Definition)
    [Microsoft.TeamFoundation.Build.Client.IBuildRequest] $BuildReq = $BuildDef.CreateBuildRequest();
    $buildserver.QueueBuild($BuildReq)

我的构建定义包括构建排队时设置的参数

问题是如何从 PS 脚本设置版本和发布参数?

更新:这个脚本脚本完成了工作

[Microsoft.TeamFoundation.Client.TfsTeamProjectCollection]$tfsc = [Microsoft.TeamFoundation.Client.TfsTeamProjectCollectionFactory]::GetTeamProjectCollection($TFSServer)
$IBS = [Microsoft.TeamFoundation.Build.Client.IBuildServer]
[Microsoft.TeamFoundation.Build.Client.IBuildServer] $buildserver = $tfsc.GetService($IBS)
[Microsoft.TeamFoundation.Build.Client.IBuildDefinition] $BuildDef = $buildserver.GetBuildDefinition($Project,$Definition)
[Microsoft.TeamFoundation.Build.Client.IBuildRequest] $BuildReq = $BuildDef.CreateBuildRequest();
$processParameters = [Microsoft.TeamFoundation.Build.Workflow.WorkflowHelpers]::DeserializeProcessParameters($BuildReq.ProcessParameters)
$processParameters.Version = "8.4.1.TEST"
$processParameters.PublishToDevEnv = $false
$BuildReq.processParameters = [Microsoft.TeamFoundation.Build.Workflow.WorkflowHelpers]::SerializeProcessParameters($processParameters)
$buildserver.QueueBuild($BuildReq)

你可以试试这个:

Add-Type -Path "C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\ReferenceAssemblies\v2.0\Microsoft.TeamFoundation.Build.Workflow.dll"
Add-Type -Path $PathToCustomBuildActivities
$processParameters = [Microsoft.TeamFoundation.Build.Workflow.WorkflowHelpers]::DeserializeProcessParameters($BuildDef.ProcessParameters)
$processParameters.Version = "foo"
$processParameters.PublishToDevEnv = "bar"
$BuildDef.processParameters = [Microsoft.TeamFoundation.Build.Workflow.WorkflowHelpers]::SerializeProcessParameters($processParameters)