2015-05-04 102 views
1

我嘗試通過PowerShell腳本在VisualStudio中打開成功構建的詳細頁面。我能夠連接到我的測試項目和某個BuildDefinition的集合。我爲每個構建都獲得了vstfs-Link,但是如何在Visual Studio中打開此鏈接? 我試着用EncodeUri,GetArtifactUrl和GetArtifactUrlExternal。對於GetArtifactUrl我得到這個錯誤:在Visual Studio中通過PowerShell腳本打開VSTFS鏈接

無法轉換爲「GetArtifactUrl」鍵入「Microsoft.TeamFoundation.ArtifactId」參數值「artId」,值爲:「vstfs:/// Build/Build/12345」:「Can not將類型「System.Uri」的「vstfs:/// Build/Build/12345」值轉換爲鍵入 「Microsoft.TeamFoundation.ArtifactId」。「

任何人都可以給我一些建議如何將vstfs鏈接轉換爲我可以在VisualStudio中打開的東西?

感謝

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

$uri = [URI]"http://MyServer:8080/tfs/DefaultCollection" 
$project = "MyProject" 
$buildDefinition = "MyBuildDefinition" 

# CONNECT 
$collection = [Microsoft.TeamFoundation.Client.TfsTeamProjectCollectionFactory]::GetTeamProjectCollection($uri) 

# BUILDS 
$buildServer = $collection.GetService([Microsoft.TeamFoundation.Build.Client.IBuildServer]) 
$buildSpec = $buildServer.CreateBuildDetailSpec($project, $buildDefinition) 

$ILinkingService = $collection.GetService([Microsoft.Teamfoundation.ILinking]) 
$CommonService = $collection.GetService([Microsoft.TeamFoundation.Common]) 

# QUERY 
$buildSpec.InformationTypes = $null 
$buildSpec.MaxBuildsPerDefinition = 5 
$buildSpec.QueryOrder = [Microsoft.TeamFoundation.Build.Client.BuildQueryOrder]::FinishTimeDescending 
$results = $buildServer.QueryBuilds($buildSpec) 

foreach($build in $results.Builds) 
{ 
    Write-Host $build.Status 
    #$testUrl = $ILinkingService.GetArtifactUrl($build.Uri) 
    $testUrl = $CommonService.EncodeUri($build.Uri) 
    Write-Host $testUrl 
} 

回答

0

首先,打開建立在Visual Studio中的細節,你可以在連接使用$build.Uriurl PARAM:

$testUrl = $build.Uri.AbsoluteUri + "?url=" + $uri.AbsoluteUri 


如果你想打開在瀏覽器中構建細節,可以使用ILinking.GetArtifactUrl,但必須明確指定過載:

$testUrl = $ILinkingService.GetArtifactUrl([string] $build.Uri) 

或許更重要的是使用TswaClientHyperlinkService

$waLinkingService = $collection.GetService([Microsoft.TeamFoundation.Client.TswaClientHyperlinkService]) 
... 
$waLinkingService.GetViewBuildDetailsUrl($build.Uri)