I have been tasked with automating our build process with msbuild. We have about twenty Visual C++ projects and twenty C# projects making it a pain to hand edit all the version strings. Our version numbers are meat-generated at build time, so we need to pass the full version string as a property on the command line. My initial implementation used the MSBuild Extension Pack's File class to do replacements on the .rc and AssemblyInfo.cs files:
<FileSystem.File TaskAction="Replace" Files="@(AssemblyInfoFiles)" RegexPattern='\[assembly: AssemblyVersion\(".*"\)\]' Replacement='[assembly: AssemblyVersion("$(Version)")]'/>
<FileSystem.File TaskAction="Replace" Files="@(AssemblyInfoFiles)" RegexPattern='\[assembly: AssemblyFileVersion\(".*"\)\]' Replacement='[assembly: AssemblyFileVersion("$(Version)")]'/>
<FileSystem.File TaskAction="Replace" Files="@(RCFiles)" RegexPattern="FILEVERSION\s+\S+" Replacement="FILEVERSION $(Version)"/>
<FileSystem.File TaskAction="Replace" Files="@(RCFiles)" RegexPattern="PRODUCTVERSION\s+\S+" Replacement="PRODUCTVERSION $(Version)"/>
<FileSystem.File TaskAction="Replace" Files="@(RCFiles)" RegexPattern='VALUE\s+"FileVersion",\s*".*"' Replacement='VALUE "FileVersion", "$(Version)"'/>
<FileSystem.File TaskAction="Replace" Files="@(RCFiles)" RegexPattern='VALUE\s+"ProductVersion",\s*".*"' Replacement='VALUE "ProductVersion", "$(Version)"'/>
This is working great on the AssemblyInfo.cs files, but when I compile any of the C++ projects I get errors like this:
.\MyProject.rc(23): error RC2135: file not found: 0x09
.\MyProject.rc(71): error RC2135: file not found: 1
.\MyProject.rc(72): error RC2135: file not found: 6
.\MyProject.rc(73): error RC2135: file not found: 6
.\MyProject.rc(74): error RC2135: file not found: 0x3fL
.\MyProject.rc(80): error RC2135: file not found: FILEOS
.\MyProject.rc(81): error RC2135: file not found: 0x2L
.\MyProject.rc(84): error RC2164: unexpected value in RCDATA
.\MyProject.rc(86): error RC2135: file not found: BLOCK
.\MyProject.rc(88): error RC2135: file not found: VALUE
The first error is encountered on line 23, but when I diff MyProject.rc against source control everything looks OK. Only the version numbers are changed, those changes begin on line 72, and the string "0x09" does not appear anywhere in the file. What in the world is going on here? Lines 21 - 25 look like this:
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#endif //_WIN32
I'm also open to any suggestions on other methods to accomplish the same goal.