【问题标题】:How to get TeamCity build version into unmanaged DLLs and OCX controls?如何将 TeamCity 构建版本转换为非托管 DLL 和 OCX 控件?
【发布时间】:2014-10-02 06:38:14
【问题描述】:

我有一个包含托管 (C#) 和非托管 (C++) 项目的 TeamCity 构建解决方案。是否有类似于 Assembly Info Patcher 的 TeamCity 实用程序可以更改非托管 C++ DLL 和 OCX 项目的 .rc 文件中的版本号以匹配内部版本号?

【问题讨论】:

    标签: dll version teamcity ocx


    【解决方案1】:

    这是我最终在 PowerShell 中完成的 StampVer 的替代方案,它在构建之前修改 .rc 文件。我对使用足够空间预先填充版本字符串的 StampVer 约束感到不舒服。

    #################################################################
    #
    # Patch all of the given *.rc files and set
    # the version strings for DLLs and OCX controls.
    #
    #################################################################
    
    
    # Hand parse the arguments so we can separate them with spaces.
    $files = @()
    
    $previousArg = "__" 
    foreach ($arg in $args)
    {
        if ($previousArg -eq "-version")
        {
            $version = $arg
        }
        elseif ($previousArg -eq "__")
        {
        }
        else
        {
            $files += $arg
        }
        $previousArg = $arg
    }
    
    Function PatchRCFiles([string]$version, [string[]]$files)
    {
        # check the version number
        if ( $version -match "[0-9]+.[0-9]+.[0-9]+.[0-9]+" )
        {
            echo "Patching all .rc files to version $version"
    
            # convert the version number to .rc format
            $rc_version = $version -replace "\.", ","
            $rc_version_spaced = $version -replace "\.", ", "
    
            # patch the files we found
            ForEach ($file In $files) 
            { 
                echo "Processing $file..."
                $content = (Get-Content $file)
                $content | 
                Foreach-Object {
                    $_ -replace "^\s*FILEVERSION\s*[0-9]+,[0-9]+,[0-9]+,[0-9]+$", " FILEVERSION $rc_version" `
                       -replace "^\s*PRODUCTVERSION\s*[0-9]+,[0-9]+,[0-9]+,[0-9]+$", " PRODUCTVERSION $rc_version" `
                       -replace "(^\s*VALUE\s*`"FileVersion`",\s*)`"[0-9]+,\s*[0-9]+,\s*[0-9]+,\s*[0-9]+`"$", "`$1`"$rc_version_spaced`"" `
                       -replace "(^\s*VALUE\s*`"ProductVersion`",\s*)`"[0-9]+,\s*[0-9]+,\s*[0-9]+,\s*[0-9]+`"$", "`$1`"$rc_version_spaced`""
                }  | 
                Set-Content $file
              }
        }
        else
        {
            echo "The version must have four numbers separated by periods, e.g. 5.4.2.123"
        }
    }
    
    PatchRCFiles $version $files
    

    TeamCity 中的配置如下所示:

    只需给脚本一个你想要调整的 .rc 文件列表。此步骤必须在主要构建步骤之前运行。

    【讨论】:

    • 我认为“FileVersion”和“ProductVersion”替换的正则表达式存在缺陷。在我的测试应用程序中,这两个属性具有这种形式:VALUE "FileVersion", "1.0.0.1"。您的正则表达式正在寻找逗号分隔的数字,然后替换间隔的版本号。我修改了表达式以查找“。”分开的数字,直接代入version参数。 -replace "(^\s*VALUE\s*"FileVersion",\s*)"[0-9]+.\s*[0-9]+.\s*[0-9]+.\s*[0-9]+"$", "$1@ 987654327@"" ` 然后此更改正确更新了 FileVersion 和 ProductVersion 详细信息。
    【解决方案2】:

    不,teamcity 没有任何东西可以更新 C++ dll 的版本,但是您可以使用 StampVer.exe 来更新 C++ dll 的版本。您需要下载 exe 并添加一个构建来调用 exe,这将更新 C++ exe 或 dll 的版本。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-03-31
      • 1970-01-01
      • 2012-04-08
      • 1970-01-01
      • 1970-01-01
      • 2010-10-14
      相关资源
      最近更新 更多