使用 TFS 2015 update 2,在计算机中安装代理,代理创建其工作区:
内部开发的一些自定义 MSBuild 任务已在将在代理上运行的生成定义中实现。这些任务针对 TFS 服务器执行一些操作。
当构建定义排队等待新构建时,我得到的是:
在构建机器中,我继续运行以下脚本,以验证工作区是否存在:
# Script to find a Team Foundation workspace
param(
[string] $workspaceHint = $(get-location).Path
)
begin
{
# load the needed client dll's
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.Client")
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.VersionControl.Client")
# fetches a Workspace instance matching the WorkspaceInfo found in the cache file
function getWorkspaceFromWorkspaceInfo($wsInfo)
{
$tfs = [Microsoft.TeamFoundation.Client.TeamFoundationServerFactory]::GetServer($wsInfo.ServerUri.AbsoluteUri)
$vcs = $tfs.GetService([Microsoft.TeamFoundation.VersionControl.Client.VersionControlServer])
$vcs.GetWorkspace($wsInfo)
# TODO: likely add some convenience properties/methods for easier scripting support
}
}
process
{
# is there only 1 workspace in our cache file? If so, use that one regardless of the hint
$workspaceInfos = [Microsoft.TeamFoundation.VersionControl.Client.Workstation]::Current.GetAllLocalWorkspaceInfo()
if ($workspaceInfos.Length -eq 1)
{
return getWorkspaceFromWorkspaceInfo($workspaceInfos[0])
}
if (test-path $workspaceHint)
{
# workspace hint is a local path, get potential matches based on path
$workspaceInfos = [Microsoft.TeamFoundation.VersionControl.Client.Workstation]::Current.GetLocalWorkspaceInfoRecursively($workspaceHint)
}
else
{
# workspace hint is NOT a local path, get potential matches based on name
$workspaceInfos = @($workspaceInfos | ?{ $_.name -match $workspaceHint })
}
if ($workspaceInfos.Length -gt 1)
{
throw 'More than one workspace matches the workspace hint "{0}": {1}' -f
$workspaceHint, [string]::join(', ', @($workspaceInfos | %{ $_.Name}))
}
elseif ($workspaceInfos.Length -eq 1)
{
return getWorkspaceFromWorkspaceInfo($workspaceInfos[0])
}
else
{
throw "Could not figure out a workspace based on hint $workspaceHint"
}
}
该脚本无法找到任何工作区。
然后,在计算机中安装 TFS 2015 Power 工具及其 powershell cmdlet,并运行以下脚本:
if ( (Get-PSSnapin -Name Microsoft.TeamFoundation.PowerShell -ErrorAction SilentlyContinue) -eq $null )
{
Add-PSSnapin -Name Microsoft.TeamFoundation.PowerShell
}
$ws = Get-TfsWorkspace -Path C:\t\1\s
$ws.Folders
显示工作区和映射的项目。
排队新的构建,继续显示相同的错误。
工作区是一个公共服务器,根据 msdn 论坛上的一些古老帖子,我清理了机器中的 TFS 缓存。
有任何线索如何使 Microsoft.TeamFoundation.VersionControl.Client 能够识别工作区吗?