如何将 TeamCity 构建版本获取到非托管 DLL 和 OCX 控件中?

2024-03-03

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


这是我最终在 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 文件列表即可。此步骤必须在主要构建步骤之前运行。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何将 TeamCity 构建版本获取到非托管 DLL 和 OCX 控件中? 的相关文章

随机推荐