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.