如何解决TFS文件夹的服务器上的根目录和相对路径? [英] How do I resolve the root and relative paths of TFS folders on the server?

查看:463
本文介绍了如何解决TFS文件夹的服务器上的根目录和相对路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个的在(自定义)利用建立的定义CodeActivity 。此活动需要执行其主要目的之前,/从像源目录,自定义文件夹到投递目录(等)的地方复制位于服务器上的文件。



有些我都有效路径,但其他人显然对相对路径占位符的变量。不过,我需要的物理服务器的路径,所以我可以用项目复制到往复



我需要的东西,如:




  • 的项目根的物理路径(见下图)

  • 要能够解析到自定义文件夹的物理路径(见下图)

  • 这将是很好,能够解决从相对路径



  • 当然,我可以通过该项目名称为活动(用于分析目的)......因为那也只是'俗气'。



    我的问题(S)为:




    • 如何解析到TFS项目的根?

    • 的物理路径一旦我解决了根,我可以依靠它来建设路径的自定义文件夹?

    • <李>如何获得像'$ /测试/滴的相对路径服务器路径?





    THINGS的某些实例我知道如何获得:

    这些项目有些是有用的,而其他...没有这么多。除非,我可以用它们来获得物理服务器的路径



    BuildDirectory:

    'F:\bld\Builds\41 \Test\Test_CustomActivity_CreateNuGetPackages



    BuildDetail.DropLocationRoot:

    '$ /测试/滴'

    。 ..wish我的物理路径



    BuildDetail.BuildController.CustomAssemblyPath:

    '$ /测试/ BuildProcessTemplates'

    ...希望我的物理路径



    SourcesDirectory:

    'F:\bld\Builds\41\ Test\Test_CustomActivity_CreateNuGetPackages\src



    Workspace.Folders:

    'F:\bld\Builds\41\Test \Test_CustomActivity_CreateNuGetPackages\src\Test\NuGet.Research\\\
    et35



    THINGS的某些实例我想要的:



    更新:2015年2月2日

    @Edward - 根据您的要求。下面是什么,我试图完成一个更详细的解释。



    在这里输入的形象描述


    解决方案

    让我说,有很多术语超载的事情前言这个答案,所以我想定义的几件事情:




    • 服务器路径:路径在版本控制系统中的文件或文件夹。例如, $ /测试/ BuildResources 服务器路径的。这是一个绝对的服务器路径,它是不是相对

    • 本地路径:已映射服务器路径到你的机器上的路径。例如, D:\Test\BuildResources /家庭/ ME /测试/ buildresources 本地路径

    • 映射:服务器路径和本地路径之间的对应关系 - 这样TFVC知道在哪里可以把你的本地计算机上的文件当你做一个搞定。



    我定义这不是迂腐,但使用的时候,因为具有术语正确会有所帮助TFS的SDK,它可以让你查询一个给定的服务器路径(反之亦然)轻松的本地路径。 (你不应该只是在连接路径组件组合在一起,因为TFVC允许对非常复杂的工作区映射。)



    要开始使用TFS SDK,首先需要找到服务器连接信息。如果你有一个给定的本地路径(在这种情况下,你的 SourcesDirectory ),你可以用它来阅读空间缓存并获得您需要的服务器连接的版本信息服务器已创建:

      //获取构建服务器的工作空间
    VAR workspaceInfo = Workstation.Current工作区的信息。 GetLocalWorkspaceInfo(sourcesDirectory);

    //从空间缓存
    //信息然后装入TFS工作区本身TFS团队项目集合的信息。
    VAR服务器=新TfsTeamProjectCollection(workspaceInfo.serverUri);
    变种工作区= workspaceInfo.GetWorkspace(服务器);



    一旦你有一个工作区,你可以查询它的路径映射。它会根据你的工作区映射执行从服务器的必要翻译本地路径。例如:

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

      workspace.GetLocalItemForServerItem($ /我的/服务器/路径); 

    这机制才起作用,但是,如果你的构建定义实际上建立工作区包含这些文件。如果你需要一些目录 $ /美孚/酒吧,你需要确保它包含在源代码设置的详细信息生成定义的标签。


    I have created a CodeActivity for use in (custom) build definitions. This activity needs to copy files located on the server to/from places like the 'source directory', 'custom folders' to the 'drop directory' (etc.) before executing its primary purpose.

    Some of the variables I have are valid paths, but others are obviously placeholders for 'relative paths'. However, I need the physical server path so I can copy useful items to-and-fro.

    I NEED THINGS LIKE:

    • The physical path for the projects root (see image below)
    • To be able to resolve the physical path to custom folders (see image below)
    • It would be nice to be able to resolve physical paths from 'relative paths'

    Of course, I could pass the project-name into the activity (for parsing purposes)...because that would just be 'cheesy'.

    MY QUESTION(S) ARE:

    • How do I resolve the physical path to the TFS project root?
    • Once I resolve the root, can I rely on it to 'build' paths to custom folders?
    • How do I get the server paths from relative paths like '$/Test/Drops'?

    SOME EXAMPLES OF THINGS I KNOW HOW TO GET:
    These items are somewhat useful, while others...not so much. Unless, I can use them to get the physical server paths.

    BuildDirectory:
    'F:\bld\Builds\41\Test\Test_CustomActivity_CreateNuGetPackages'

    BuildDetail.DropLocationRoot:
    '$/Test/Drops'
    ...wish I had the physical path

    BuildDetail.BuildController.CustomAssemblyPath:
    '$/Test/BuildProcessTemplates'
    ...wish I had the physical path

    SourcesDirectory:
    'F:\bld\Builds\41\Test\Test_CustomActivity_CreateNuGetPackages\src'

    Workspace.Folders:
    'F:\bld\Builds\41\Test\Test_CustomActivity_CreateNuGetPackages\src\Test\NuGet.Research\net35'

    SOME EXAMPLES OF THINGS I WANT:

    UPDATE: 2/2/2015
    @Edward - per your request. Below is a more detailed explanation of what I am trying to accomplish.

    解决方案

    Let me preface this answer by saying that there's a lot of terminology overload going on, so I want to define a few things:

    • Server path: the path to the file or folder in the version control system. For example, $/Test/BuildResources is a server path. This is an absolute server path, it is not relative.
    • Local path: the path that you have mapped the server path to on your machine. For example, D:\Test\BuildResources or /home/me/test/buildresources is a local path.
    • Mapping: the correspondence between the server paths and local paths - so that TFVC knows where to put files on your local machine when you do a "get".

    I define this not to be pedantic, but because having the terminology correct will be helpful when using the TFS SDK, which will let you query the local path for a given server path (and vice versa) easily. (You should not simply concatenate path components together, since TFVC allows for very complex workspace mappings.)

    To get started with the TFS SDK, you first need to find the server connection information. 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 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.

    这篇关于如何解决TFS文件夹的服务器上的根目录和相对路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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