title: Using MSBuild to update the FILEVERSION in a C++ resource file causes compile failures
body: <p>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.</p>
  
  <p>My initial implementation used the <a href="http://msbuildextensionpack.codeplex.com/" rel="noreferrer">MSBuild Extension Pack</a>'s <a href="http://www.msbuildextensionpack.com/help/3.5.3.0/html/f8c545f9-d58f-640e-3fce-b10aa158ca95.htm" rel="noreferrer"><code>File</code></a> task to do replacements on the <code>.rc</code> and <code>AssemblyInfo.cs</code> files.</p>
  
  <pre><code>&lt;FileSystem.File TaskAction="Replace" Files="@(AssemblyInfoFiles)" RegexPattern='\[assembly: AssemblyVersion\(".*"\)\]' Replacement='[assembly: AssemblyVersion("$(Version)")]'/&gt;
  &lt;FileSystem.File TaskAction="Replace" Files="@(AssemblyInfoFiles)" RegexPattern='\[assembly: AssemblyFileVersion\(".*"\)\]' Replacement='[assembly: AssemblyFileVersion("$(Version)")]'/&gt;
  &lt;FileSystem.File TaskAction="Replace" Files="@(RCFiles)" RegexPattern="FILEVERSION\s+\S+" Replacement="FILEVERSION $(Version)"/&gt;
  &lt;FileSystem.File TaskAction="Replace" Files="@(RCFiles)" RegexPattern="PRODUCTVERSION\s+\S+" Replacement="PRODUCTVERSION $(Version)"/&gt;
  &lt;FileSystem.File TaskAction="Replace" Files="@(RCFiles)" RegexPattern='VALUE\s+"FileVersion",\s*".*"' Replacement='VALUE "FileVersion", "$(Version)"'/&gt;
  &lt;FileSystem.File TaskAction="Replace" Files="@(RCFiles)" RegexPattern='VALUE\s+"ProductVersion",\s*".*"' Replacement='VALUE "ProductVersion", "$(Version)"'/&gt;
  </code></pre>
  
  <p>This is working great on the <code>AssemblyInfo.cs</code> files, but when I compile any of the C++ projects I get errors like this:</p>
  
  <pre><code>.\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
  </code></pre>
  
  <p>The first error is encountered on line 23, but when I diff <code>MyProject.rc</code> against source control everything looks OK.  Only the version numbers are changed, those changes begin on line 72, and the string <code>0x09</code> does not appear anywhere in the file.  What in the world is going on here?  Lines 21 - 25 look like this:</p>
  
  <pre><code>#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
  #ifdef _WIN32
  LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
  #pragma code_page(1252)
  #endif //_WIN32
  </code></pre>
  
  <p>I'm also open to any suggestions on other methods to accomplish the same goal.</p>