代码之家  ›  专栏  ›  技术社区  ›  Serge van den Oever

确定本地文件夹(Subversion或TFS)使用的源代码管理系统

  •  2
  • Serge van den Oever  · 技术社区  · 17 年前

    摘要:如何确定本地文件夹的TFS源代码管理配置。

    说明:

    在我们的软件工厂中,我根据源代码管理系统中的代码所在的本地文件夹自动创建CruiseControl.NET配置文件。我目前只想支持Subversion和TFS。使用svn.exe info命令可以轻松确定Subversion用作源代码管理系统,并确定存储库的位置,如下面的PowerShell代码所示。但是,当使用TFS时,我如何做到这一点?

    “问题”之一是当前登录的用户没有访问TFS服务器的权限。我们无法使用集成安全性,因为开发人员计算机未加入域。

    我得到的最接近的是tf dir,我必须在弹出框中输入凭证。找不到用于指定用户和密码的命令行参数。tf属性看起来也很有希望,但您必须经过身份验证才能执行调用。Subversion可以提供无需身份验证的信息。

    注意,对于CruiseCOntrol.NET块的实际创建,我们在全局变量中配置了一个源代码管理用户名和密码。

    #
    #   
    #       
    #           https://svn.mycompany.nl/svn/Acme.Intranet
    #       
    #   
    #
    #   If under source control return a CruiseControl.NET source control configuration block in
    #   the following format:
    #   
    #       https://svn.mycompany.nl/svn/Acme.Intranet
    #       c:\project\Acme.Intranet.Build\WorkingDirectory\$configuration
    #       acmebuild
    #       acmepassword
    #           
    #.Parameter configuration
    #   Either "Debug" or "Release"
    # .Returns
    #   A string with the configuration block, or $null if not under Subversion source control.
    ##>
    function GetSubversionSourceControlBlock
    {
        param
        (
            $configuration
        )
    
        $svn_exe = Join-Path -Path $productfolder -ChildPath "tools\DotNet2\svn-win32-1.5.2\svn.exe"
        $svnProductInfo = [xml](& $svn_exe info `"$productFolder`" --xml)
        $trunkUrl = $svnProductInfo.info.entry.url
        if ($trunkUrl -ne $null)
        {
    @"
            
                $trunkUrl
                $buildfolder\WorkingDirectory\$configuration
                $MastConfigurationGlobal_SourceControlUserName
                $MastConfigurationGlobal_SourceControlPassword
                    
    "@
            Verbose "Under Subversion source control. Trunk Url: $trunkUrl"
        }
        else
        {
            Verbose "Not under Subversion source control"
            $null
        }
    }   
    
    #
    #       tfs.mycompany.nl
    #       $/Acme.Intranet
    #       c:\project\Acme.Intranet.Build\WorkingDirectory\$configuration
    #       acmebuild
    #       acmepassword
    #           
    #.Parameter configuration
    #   Either "Debug" or "Release"
    # .Returns
    #   A string with the configuration block, or $null if not under Tfs source control.
    ##>
    function GetTfsSourceControlBlock
    {
        param
        (
            $configuration
        )
    
        $null
    }   
    
    2 回复  |  直到 17 年前
        1
  •  2
  •   Serge van den Oever    17 年前

    故事继续:

    如果从cmd提示符执行tf命令,则一切都将按照前面的回答进行。如果在PowerShell命令提示符下执行此操作,则会得到以下结果:

    PS C:\> & tf.exe workfold c:\projects\Macaw.SolutionsFactory\FactoryIdeTools\trunk /login:macaw\serge,Trasimeno5
    TF10125: The path 'c:\projects\Macaw.SolutionsFactory\FactoryIdeTools\trunk' must start with $/
    

    我什么都试过了,但没有用。我甚至通过TFS对象模型进行了尝试,但这变得非常复杂。要获取本地文件夹的工作区,首先需要tfs服务器的名称。可能会迭代所有当前映射的工作区,并迭代其中定义的服务器(这可能是tf.exe所做的),以测试本地文件夹是否属于该工作区。

    我最终提出了以下解决方案:

    @echo off
    rem This is a kind of strange batch file, needed because execution of this command in PowerShell gives an error.
    rem This script retrieves TFS sourcecontrol information about a local folder using the following command:
    rem tf workfold  /login:domain\user,password
    rem %1 is path to the tf.exe executable
    rem %2 is the local path
    rem %3 is the domain\user [optional, integrated security used if ommited]
    rem %4 is the password    [optional, if %3 is not specified]
    rem Output is in format:
    rem ===============================================================================
    rem Workspace: Macaw.SolutionsFactory@VS-D-SVDOMOSS-1 (Serge)
    rem Server   : tfs.macaw.nl
    rem $/Macaw.SolutionsFactory/FactoryIdeTools/trunk: C:\Projects\Macaw.SolutionsFactory\FactoryIdeTools\trunk
    
    if [%3]==[] goto integratedsecurity
    %1 workfold "%2" /login:%3,%4
    goto end
    
    :integratedsecurity
    %1 workfold "%2"
    
    :end
    

    我从PowerShell中调用此批处理脚本。根据我要分析的结果:

    • Tfs服务器名称
    • 服务器上的文件夹

    $tfsProductInfo = & "ExecTfWorkprodCommand.bat "C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\TF.exe" "c:\projects\Macaw.SolutionsFactory\FactoryIdeTools\trunk" domain\user password
    if ($tfsProductInfo -eq $null)
    {
        Write-Output "Can't determine Tfs source control information on local folder"
    }
    else
    {
        $tfsserver = [Regex]::Split($tfsProductInfo[2], ": ")[1].Trim()
        $serverpath = [Regex]::Split($tfsProductInfo[3], ": ")[0].Trim()
        $localpath = [Regex]::Split($tfsProductInfo[3], ": ")[1].Trim()
        Write-Output "Server     : $tfsserver"
        Write-Output "Server path: $serverpath"
        Write-Output "Local path : $localpath"
    }
    
        2
  •  1
  •   Serge van den Oever    17 年前

    好的,我自己找到了答案。首先:有一个wat来指定tf.exe命令行工具的凭据。使用/登录:域\用户,密码。

    现在如果我执行:

    tf workfold c:\projects\Macaw.SolutionsFactory\FactoryIdeTools\trunk /login:domain\user,password
    

    我得到以下结果:

    ===========================================================================================================================================
    Workspace: Macaw.SolutionsFactory@VS-D-SVDOMOSS-1 (Serge)
    Server   : tfs.mycompany.nl
     $/Macaw.SolutionsFactory/FactoryIdeTools/trunk: C:\Projects\Macaw.SolutionsFactory\FactoryIdeTools\trunk
    

    这就是我需要的所有信息!