2017-07-03 22 views

回答

1

您可以使用下面的腳本來獲取特定項目的最新標籤:

#Add Reference Assemblies to be loaded accordingly based on your VS client. 

add-type -Path 'C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\Microsoft.TeamFoundation.VersionControl.Client.dll' 
add-type -Path 'C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\Microsoft.TeamFoundation.Client.dll' 

$CollectionUrl = 'http://servername:8080/tfs/DefaultCollection' 
$tfs = [Microsoft.TeamFoundation.Client.TfsTeamProjectCollectionFactory]::GetTeamProjectCollection($CollectionUrl) 
$vcs = $tfs.GetService([Microsoft.TeamFoundation.VersionControl.Client.VersionControlServer]) 
$labels = $vcs.QueryLabels('*','$/ProjectName',$null,$true) 
$latestlabel = $labels | Select-Object -first 1 

write-host "The Latest Lable Name:" $latestlabel.Name 
write-host "The Latest Lable ID :" $latestlabel.LabelID 
+0

喜@安迪MSFT ::我嘗試過,以及提到的命令,但它給我空值。請檢查並幫助我瞭解如果我在這裏丟失了任何東西(我只提到了我修改過的行) - $ CollectionUrl ='http:// servername:8080/tfs' $ tfs = [Microsoft.TeamFoundation.Client。 TFSTeamProjectCollectionFactory] ​​:: GetTeamProjectCollection($ CollectionUrl) $ vcs = $ tfs.GetService([Microsoft.TeamFoundation.VersionControl.Client.VersionControlServer]) $ labels = $ vcs.QueryLabels('*','$/project path/project .sln',$ null,$ true) $ latestlabel = $ labels | Select-Object -first 1 –

+0

@PratikBompilwar請同時將'$/ProjectName'改爲真正的項目名稱,但不是'$/project path/project.sln',例如:如果項目名稱是「Test」,只需設置它作爲$/Test –

+0

謝謝,@ Andy-MSFT。這樣可行。你有任何想法,如果我可以使用任何過濾器標籤名稱。假設我想搜索一些從「test ***。***。*」開始的標籤。我們可以使用任何包含(測試)的東西嗎? –