我正在尝试从PowerShell脚本更新构建定义,但在尝试反序列化过程参数时遇到了问题。
我的剧本
add-type -Path 'C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\ReferenceAssemblies\v2.0\Microsoft.TeamFoundation.Client.dll'
add-type -Path 'C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\ReferenceAssemblies\v2.0\Microsoft.TeamFoundation.Build.Client.dll'
add-type -Path 'C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\ReferenceAssemblies\v2.0\Microsoft.TeamFoundation.Build.Common.dll'
add-type -Path 'C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\ReferenceAssemblies\v2.0\Microsoft.TeamFoundation.Build.Workflow.dll'
$tfsCollectionUrl = "http://{myurl}/tfs/{mycollection}"
$server = new-object Microsoft.TeamFoundation.Client.TfsTeamProjectCollection(New-Object Uri($tfsCollectionUrl))
$buildServer = $server.GetService([Microsoft.TeamFoundation.Build.Client.IBuildServer])
$buildDef = $buildServer.GetBuildDefinition("{MyProjectName}", "{MyBuildName}")
$processParams = [Microsoft.TeamFoundation.Build.Workflow.WorkflowHelpers]::DeserializeProcessParameters($buildDef.ProcessParameters)
$processParams
错误
Exception calling "DeserializeProcessParameters" with "1" argument(s): "Set property 'Microsoft.TeamFoundation.Build.Common.BuildParameter.Json' threw an exception."
At line:14 char:1
+ $processParams = [Microsoft.TeamFoundation.Build.Workflow.WorkflowHel ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : XamlObjectWriterException
我所看到的关于如何做我想做的事情(更新内部版本编号格式)的一切都给了我这个确切的代码,所以不知道从哪里开始。构建定义和流程参数确实会回来,而不是我真正可以使用的方式。
我们使用的是TFS 2013 Update 4,cmdlet来自2013 TFS PowerTools。
答案 0 :(得分:1)
我错过了对Newtonsoft.Json.dll的引用:
Add-Type -Path "C:\Folder\SharedAssemblies\Newtonsoft.Json.dll"
我补充说,一切都很好。
最终剧本:
Add-Type -Path "C:\{Folder}\SharedAssemblies\Newtonsoft.Json.dll"
Add-Type -Path "C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\ReferenceAssemblies\v2.0\Microsoft.TeamFoundation.Client.dll"
Add-Type -Path "C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\ReferenceAssemblies\v2.0\Microsoft.TeamFoundation.Build.Client.dll"
Add-Type -Path "C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\ReferenceAssemblies\v2.0\Microsoft.TeamFoundation.Build.Workflow.dll"
$tfsCollectionUrl = "http://{myurl}/tfs/{mycollection}"
$server = new-object Microsoft.TeamFoundation.Client.TfsTeamProjectCollection(New-Object Uri($tfsCollectionUrl))
$buildServer = $server.GetService([Microsoft.TeamFoundation.Build.Client.IBuildServer])
$buildDefinition = $buildServer.GetBuildDefinition("{MyProjectName}", "{MyBuildName}")
$processParams = [Microsoft.TeamFoundation.Build.Workflow.WorkflowHelpers]::DeserializeProcessParameters($buildDefinition.ProcessParameters)
$processParams.BuildNumberFormat = "`$(BuildDefinitionName)_`$(Year:yy).222.0`$(Rev:.r)"
$buildDefinition.ProcessParameters = [Microsoft.TeamFoundation.Build.Workflow.WorkflowHelpers]::SerializeProcessParameters($processParams)
$buildDefinition.Save()