How to get TeamCity build version into unmanaged DLLs and OCX controls?

吃可爱长大的小学妹 提交于 2019-12-11 01:59:31

问题


I have a TeamCity build solution with managed (C#) and unmanaged (C++) projects. Is there a TeamCity utility out there similar to Assembly Info Patcher that will change the version numbers in the .rc files for unmanaged C++ DLL and OCX projects to match the build number?


回答1:


No, teamcity doesn't have anything to update version of C++ dlls, you could however use StampVer.exe to update the version of C++ dlls. You'll need to download the exe and add a build to call the exe which will update the version of the C++ exe or dll.




回答2:


Here's an alternative to StampVer that I ended up doing in PowerShell, which modifies the .rc files prior to the build. I wasn't comfortable with the StampVer constraints of pre-filling the version strings with sufficient space.

#################################################################
#
# 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

The configuration in TeamCity then looks like this:

Just give the script a list of .rc files you want to tweak. This step must be run prior to the main build steps.



来源:https://stackoverflow.com/questions/25209311/how-to-get-teamcity-build-version-into-unmanaged-dlls-and-ocx-controls

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!