我正在尝试使用powershell和tfs api创建一个新的工作项类型。
这是我尝试运行以创建新工作项类型
的脚本[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.Client")
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.Build.Client")
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.Build.Common")
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.WorkItemTracking.Client")
[string] $tfsCollectionUrl = "http://r2-09-tfs:8080/tfs/DefaultCollection"
$teamProjectCollection = [Microsoft.TeamFoundation.Client.TfsTeamProjectCollectionFactory]::GetTeamProjectCollection($tfsCollectionUrl)
$ws = $teamProjectCollection.GetService([type]"Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore")
$proj = $ws.Projects["TestTeamProject"]
$wit = $proj.WorkItemTypes["Task"]
$workitem = $wit.NewWorkItem()
$workItem.Title = "Sample Task Title 2"
$workItem.Description = "Sample Description"
$workitem.AreaPath = "TestTeamProject"
$workitem.IterationPath = "TestTeamProject"
$workItem.Save()
Write-Host "The TFS work item number is: " $workItem.Id
当我运行此脚本时,收到一条错误,指出无法索引到空数组。在$ proj = $ ws.Projects [" TestTeamProject"]
我的猜测是workitemstore变量$ ws为null,我错过了该行中的任何内容吗?
答案 0 :(得分:0)
[void]System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.Client")
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.Build.Client")
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.Build.Common")
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.WorkItemTracking.Client")
[string] $tfsCollectionUrl = "http://r2-09-tfs:8080/tfs/DefaultCollection"
$teamProjectCollection = [Microsoft.TeamFoundation.Client.TfsTeamProjectCollectionFactory]::GetTeamProjectCollection($tfsCollectionUrl)
[Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore]$ws = $teamProjectCollection
$proj = $ws.Projects["TestTeamProject"]
$wit = $proj.WorkItemTypes["Task"]
$workitem = $wit.NewWorkItem()
$workItem.Title = "Sample Task Title 2"
$workItem.Description = "Sample Description"
$workitem.AreaPath = "TestTeamProject"
$workitem.IterationPath = "TestTeamProject"
$workItem.Save()
Write-Host "The TFS work item number is: " $workItem.Id
将$ ws类型更改为Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore类型并取消了GetService,现在工作正常...