TFS生成定义的Powershell脚本

TFS生成定义的Powershell脚本,tfs,build-process,Tfs,Build Process,我正在尝试创建powershell脚本以创建TFS生成定义。我用C#创建了这个示例()。但是,我在创建构建定义时遇到困难 我的剧本: param( [Parameter(Mandatory=$true)] [string] $buildName,`enter code here` [string] $teamProject="Templates", [string] $buildTemplateName = "TestBuildTemplate", [string] $buildDescript

我正在尝试创建powershell脚本以创建TFS生成定义。我用C#创建了这个示例()。但是,我在创建构建定义时遇到困难

我的剧本:

param(
[Parameter(Mandatory=$true)]
[string] $buildName,`enter code here`
[string] $teamProject="Templates",
[string] $buildTemplateName = "TestBuildTemplate",
[string] $buildDescription = "Test Descirption",
[string] $buildController = "TFS - Controller"
)

Clear-Host

$ErrorActionPreference = “Stop” ;
if ($Verbose) { $VerbosePreference = “Continue” ; }

$assemblylist = 
"Microsoft.TeamFoundation.Build.Client",
"Microsoft.TeamFoundation.Build.Workflow",
"Microsoft.TeamFoundation.Client",
"Microsoft.TeamFoundation.Common",
"Microsoft.TeamFoundation.WorkItemTracking.Client"

Write-Verbose -Message “Loading TFS Build assembly…”

foreach ($asm in $assemblylist)
{
    $asm = [Reflection.Assembly]::LoadWithPartialName($asm)
}

 $tfsCollectionUrl = "TFS Server IP Address"

 $server.EnsureAuthenticated()
 if(!$server.HasAuthenticated)
 {
    Write-Host "Failed to authenticate TFS"
    exit
 }

 Write-Host "Connected to TFS...."

 $buildServer = $server.GetService([Microsoft.TeamFoundation.Build.Client.IBuildServer])

 $def = $buildserver.CreateBuildDefinition($teamProject)
 $def.Name = $buildTemplateName
 $def.Description = $buildDescription


 $def.Workspace.AddMapping("$/Default/Sampleapplication1", '"$(SourceDir)"', 0)
 $def.Workspace.AddMapping('"$/OtherPath/"', "", 1)

 $def.BuildController = $buildserver.GetBuildController($buildController)
 $def.DefaultDropLocation = "Drop Location Share"


 $def.Save()

我遇到的错误无法另存为未定义的进程。我在这里遗漏了什么?

这是不言自明的,你似乎遗漏了博客标题“过程”下的整个部分。流程定义(要构建的项目)对于保存构建定义是必需的,就像通过UI进行时一样。我应该更准确地回答我的问题。我试图实现博客中显示的流程部分。但是我在WorkflowHelpers.DeserializeProcessParameters(buildDefinition.ProcessParameters)中遇到了问题;和BuildSettings=newBuildSettings();部分。我遇到的一个错误是,当我编写“varprocess=WorkflowHelpers.DeserializeProcessParameters(buildDefinition.ProcessParameters);”部分代码时,“不能对空值表达式调用方法”。我不确定这里发生了什么,或者我的脚本错了。我正在寻找一个如何写的例子。