即使工作空间存在并且具有映射,Microsoft.TeamFoundation.VersionControl.Client.ItemNotMappedException [英] Microsoft.TeamFoundation.VersionControl.Client.ItemNotMappedException even when the workspace exists and has a mapping

查看:64
本文介绍了即使工作空间存在并且具有映射,Microsoft.TeamFoundation.VersionControl.Client.ItemNotMappedException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用TFS 2015更新2,在计算机中安装了代理,该代理创建其工作空间:

Using TFS 2015 update 2, an agent was installed in a machine, the agent creates its workspace:

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

Some custom MSBuild tasks developed InHouse were implemented in the build definition that will run on the agent. Those tasks perform some operations against the TFS server.

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

When the build definition is queued for a new build here is what I got:

在构建机器中,我继续运行以下脚本,以验证工作空间的存在:

In the build machine I proceed to run the following script, in order to verify the existence of the workspace :

# 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"
    }
}

该脚本无法找到任何工作空间.

The script is not able to find any workspace.

然后,将TFS 2015 Power工具及其powershell cmdlet安装在计算机中,并运行以下脚本:

Then, the TFS 2015 Power tools were installed with its powershell cmdlets in the machine and run the following script:

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

显示工作区和映射的项目.

Showing the workspace and the items mapped.

正在对新版本排队,继续显示相同的错误. 工作区是一个公共服务器,工作区是在msdn论坛中的一些古老帖子之后,我清理了计算机中的TFS缓存.

Queuing new builds, keep showing the same error. The workspace is a public server one, and following some ancient post in msdn forums, I clean the TFS cache in the machine.

任何线索如何使Microsoft.TeamFoundation.VersionControl.Client能够识别工作区?

Any clue how to make the Microsoft.TeamFoundation.VersionControl.Client be able to recognize the workspace?

推荐答案

我通过运行以下PowerShell脚本来解决了计算机上的ItemNotMappedException问题;

I fixed the ItemNotMappedException problem on my machine by running something like the following PowerShell script;

$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 

您将需要更改初始变量以匹配您的环境.

You will need to change the initial variables to match your environment.

希望有帮助

这篇关于即使工作空间存在并且具有映射,Microsoft.TeamFoundation.VersionControl.Client.ItemNotMappedException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆