TFS 2013 将服务器路径转换为本地路径 [英] TFS 2013 convert server path to local path

查看:26
本文介绍了TFS 2013 将服务器路径转换为本地路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何将像$/Test/BuildResources"这样的服务器路径转换为例如:D:\test\etc.."

我正在运行 TFS 2013.我会使用GetWorkspace"项目吗?

当我尝试使用GetWorkspace"并在 Name 字段中指定 "$/Test" 时,我收到一条错误消息.不确定这是否是这样做的方法.谢谢

这是我试过的.这是我的设置:

我正在尝试将$/IW_Xavier/Deployment"转换为本地路径

我还添加了 GetWorkspace 并将其设置如下:

但它不会转换它:

我收到一条错误消息.我也尝试过使用 "GetLocalPath" - 不确定这是否符合我的要求,但它也不起作用.

编辑 2:

这就是我最终做的:1.在来源设置"中增加了路径

  1. 在Process"选项卡下,我将服务器路径存储在变量DeploymentScript"中
  2. 从工具箱中添加了GetLocalPath"并为输出使用了一个变量

这对我有用.我得到了#\IT_dfj"等的本地路径(C:\blah\blah...)非常感谢

解决方案

您不必转换它.如果您已经知道服务器路径,则可以使用此方法直接获取工作区

<小时>

更新

对不起,误会了,我终于明白你在做什么了.

首先,工作区仅代表此,因此获取工作区和工作区名称将返回:FABRIKAM-1

这是源控制文件夹和本地文件夹,这是一个映射关系.当然,这是在您的开发机器中.

但是,您想要将服务器路径转换为本地路径,想要获取 MSTest 文件的路径,但这是在您的构建代理上运行的.所以你不需要在你的开发机器中寻找它,你只需要在构建代理上寻找路径.

您正在寻找的仍然是 TF_BUILD_BUILDDIRECTORY(构建代理工作目录).然后添加相对路径,例如xx\..\...正如这个案例所说,TFS 如何获取环境变量值 .无法直接通过自定义流程获取.

所以.......最终的解决方案.建议您在构建过程中运行 脚本 或者使用 2015 新构建(vNext build),那么一切都应该没问题.:)

How would I convert server path like "$/Test/BuildResources" to ex: "D:\test\etc.."

I'm running TFS 2013. Would I use "GetWorkspace" item?

When I try to use "GetWorkspace" and specify "$/Test" in the Name field I get an error message. Not sure if this is the way to do it. thanks

EDIT:

This is what I tried. This is my setup:

I'm trying to convert "$/IW_Xavier/Deployment" to local path

I also added GetWorkspace and set it up like this:

But it doesn't convert it:

I get an error message. I also tried using "GetLocalPath"-not sure if this does what I want but it also doesn't work.

EDIT 2:

This is what I ended up doing: 1. Added the path in "Source Settings"

  1. Under "Process" tab I store a server path in a variable "DeploymentScript"
  2. Added "GetLocalPath" from the toolbox and used a variable for Output

This worked for me. I get a local path (C:\blah\blah...) for "#\IT_dfj" etc Thanks a lot

解决方案

You don't have to convert it. If you already know the server path,you can directly get the workspace by using this method Workspace.GetLocalItemForServerItem

Please refer the answer from Edward Thomson which including very detailed explanation about using TFS API to query server and local path.

If you have a given local path (in this case, your SourcesDirectory) you can use that to read the workspace cache and get the information you need for the server connection that the build server has created:

// Get the workspace information for the build server's workspace
 var workspaceInfo = Workstation.Current.GetLocalWorkspaceInfo(sourcesDirectory);

// Get the TFS Team Project Collection information from Edward Thomson  the workspace cache
// information then load the TFS workspace itself.
 var server = new TfsTeamProjectCollection(workspaceInfo.serverUri);
 var workspace = workspaceInfo.GetWorkspace(server);

Once you have a workspace, you can query it for the path mappings. It will do the necessary translation from server to local path based on your workspace mappings. For example:

workspace.GetServerItemForLocalItem("D:\My\Local\Path");

and

workspace.GetLocalItemForServerItem("$/My/Server/Path");

This mechanism will only work, however, if your build definition actually sets up the workspace to include these files. If you need some directory $/Foo/Bar, you will need to make sure that it is included in the Source Settings details tab of the Build Definition.

Source: How do I resolve the root and relative paths of TFS folders on the server?

Moreover, if you have to convert both, you can also use an ConvertWorkspaceItem activity to achieve it.

And in "GetWorkspace" activity for the Name field, you must specify a workspace name(such as "MyWorkspace" ) or a variable which get the workspace name.


Updated

Sorry for the misunderstanding, finally I got what you're doing.

First, The workspace only stand for this, so the get workspace and workspace name will return :FABRIKAM-1

And this is source control folder and local folder, this is a mapping Relationship. Of course this is in your dev machine.

However, you want to convert the server path to local path , want to get the path of MSTest file, but this is running on your build agent. So you don't need to looking for it in your dev machine, you just need to looking for the path on build agent.

What you are looking for is still the TF_BUILD_BUILDDIRECTORY (The build agent working directory). Then add the Relative path such as xx\..\... Just as this case said, TFS How to GetEnvironmentVariable value . You can't get it directly through the custom process.

So .......the ultimate solution. Suggest you to run a script in your build process or use the 2015 new build (vNext build), then everything should be OK. :)

这篇关于TFS 2013 将服务器路径转换为本地路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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