2012-07-17 26 views
1

我正在使用powershell腳本執行構建。我需要根據傳遞給腳本的命令行參數傳遞進程參數運行時。我使用TFS 2010傳遞ProcessParameters運行時(MSBuildArguments)使用Powershell到tfs 2010構建定義

[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.Client") 
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.Build.Client") 

$projectName = "test" 
$buildName = "test.Build" 
$tfsServer="xxx" 
$tfsInstance = [Microsoft.TeamFoundation.Client.TeamFoundationServerFactory]::GetServer($tfsServer) 
$buildService = $tfs.GetService([Microsoft.TeamFoundation.Build.Client.IBuildServer]) 
$buildDefinations = $buildService.QueryBuildDefinitions($projName) 

遍歷所有這些版本找到我們正在尋找

foreach ($build in $buildDefinations) 
{ 

一個得到這個名字建立實例

$bNameInstance = $build.Name 

    $ClientName = "test1" #default set in the builddefination is "/p:xxx=test" 

    #Get the process parameters. I need to update the default value. How can we process the dictionary and update the value 
    $bMSBuildArguments = $build.ProcessParameters 

    #Once setting is done."/p:xxx=test1" 
    $build.ProcessParameters = $bMSBuildArguments 

    [Void]$buildService.QueueBuild($build)  

} 

我需要幫助在更新使用PowerShell代碼的進程參數。我碰到了C#(http://blogs.msdn.com/b/jpricket/archive/2010/03/25/tfs2010-queuing-a-build-from-code-with-custom-process-parameter-values.aspx)solution,但不能將其轉換成Powershell的

回答

3

答案是在博客中提供的嘗試是這樣的:

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.Build.Workflow") 
$request = $build.CreateBuildRequest() 
$process = [Microsoft.TeamFoundation.Build.Workflow.WorkflowHelpers]::DeserializeProcessParameters($build.ProcessParameters) 

#make changes to your process parameters in $process 
$process.Item("asdf") = "new value" 

$request.ProcessParameters = [Microsoft.TeamFoundation.Build.Workflow.WorkflowHelpers]::SerializeProcessParameters($process) 

$buildService.QueueBuild($request)