我尝试通过PowerShell脚本打开VisualStudio中成功构建的详细信息页面。我能够连接到我的测试项目和某个Builddefinition的集合。我为每个构建都有一个vstfs-Link但是如何在Visual Studio中打开这个链接? 我尝试使用EncodeUri,GetArtifactUrl和GetArtifactUrlExternal。对于GetArtifactUrl,我收到此错误:
无法将参数" artId",转换为值:" vstfs:/// Build / Build / 12345",for" GetArtifactUrl"键入" Microsoft.TeamFoundation.ArtifactId":"无法转换" vstfs:/// Build / Build / 12345"类型的值" System.Uri"输入 " 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 :(得分:0)
首先,要在Visual Studio中打开构建详细信息,您只需将$build.Uri
与url
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)