即使工作空间存在且具有映射

时间:2017-01-27 20:13:42

标签: tfs msbuild tfs2015

使用TFS 2015更新2,代理程序安装在计算机中,代理程序创建其工作区:

enter image description here

在InHouse中开发的一些自定义MSBuild任务是在将在代理上运行的构建定义中实现的。这些任务对TFS服务器执行一些操作。

当构建定义排队等待新构建时,我得到的是:

enter image description here

在构建机器中,我继续运行以下脚本,以验证工作区是否存在:

# 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能够识别工作区?

3 个答案:

答案 0 :(得分:4)

我通过运行类似以下PowerShell脚本的东西修复了我的机器上的ItemNotMappedException问题;

$localReference = "C:\Repository\Project\Project.sln"
$teamProjectCollection="http://tfsserver:8080/tfs/projectcollection"
$username = $env:UserName


Add-type -AssemblyName "Microsoft.TeamFoundation.Client, Version=12.0.0.0, Culture=Neutral, PublicKeyToken=b03f5f7f11d50a3a"
Add-type -AssemblyName "Microsoft.TeamFoundation.Common, Version=12.0.0.0, Culture=Neutral, PublicKeyToken=b03f5f7f11d50a3a"
Add-type -AssemblyName "Microsoft.TeamFoundation.VersionControl.Client, Version=12.0.0.0, Culture=Neutral, PublicKeyToken=b03f5f7f11d50a3a"
Add-type -AssemblyName "Microsoft.TeamFoundation.VersionControl.Common, Version=12.0.0.0, Culture=Neutral, PublicKeyToken=b03f5f7f11d50a3a"

$folder = [System.IO.Path]::GetDirectoryName($localReference);
Push-Location $folder;

$tfsTeamProjectCollection = New-Object Microsoft.TeamFoundation.Client.TfsTeamProjectCollection($teamProjectCollection)
$versioncontrolServer = $tfsTeamProjectCollection.GetService([Microsoft.TeamFoundation.VersionControl.Client.VersionControlServer])
[Microsoft.TeamFoundation.VersionControl.Client.Workstation]::Current.EnsureUpdateWorkspaceInfoCache($versionControlServer, $username); 
$workspace = $versioncontrolServer.GetWorkspace($localReference)
echo $workspace

Pop-Location 

您需要更改初始变量以符合您的环境。

希望有所帮助

答案 1 :(得分:2)

最近,我遇到了类似的问题,它抛出了错误消息:“'映射路径'没有工作文件夹映射”

尝试使用以下命令获取工作区路径。

tf workspaces /format:detailed /owner:UserName /collection:http://TFSurl:8080/tfs

映射似乎很好。

使用Workstation.EnsureUpdateWorkspaceInfoCache就像宝石一样。

使用以下链接获取示例代码: How to call GetWorkspace in TFS properly?

答案 2 :(得分:-1)

请在脚本中添加Microsoft.TeamFoundation.Common程序集,然后重试。

 # load the needed client dll's
        [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.Client")    
        [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.Common")
        [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.VersionControl.Client")