Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pre-build MSBuild task to update AssemblyInfo not in sync with built exe

Tags:

I am using a pre-build task in Visual Studio 2008 that invokes msbuild:

C:\WINDOWS\Microsoft.NET\Framework\v3.5\MSBuild.exe $(MSBuildProjectDirectory)\version.targets /p:Configuration=$(ConfigurationName) 

Inside version.targets, I am updating the AssemblyInfo.cs file to replace version information:

   <FileUpdate         Encoding="ASCII"         Files="$(MSBuildProjectDirectory)\Properties\AssemblyInfo.cs"         Regex="AssemblyInformationalVersion\(&quot;.*&quot;\)\]"          ReplacementText="AssemblyInformationalVersion(&quot;Product $(ConfigurationString) ($(buildDate))&quot;)]"     /> 

When I build the project through Visual Studio 2008, it builds without any problems.

But when I look at the resulting exe's version information, it contains the previous time stamp even though the AssemblyInfo.cs has been changed with the "correct" one.

It seems that the pre-build's changes aren't seen by the main compilation task and it's always one behind.

Any ideas of what I'm doing wrong?

like image 488
Richard Morgan Avatar asked Feb 12 '09 14:02

Richard Morgan


2 Answers

I don't think you are doing anything wrong - it's a bug.

I have reported it here - check if you can reproduce it and add a validation, maybe we can get it fixed by MS.

EDIT: I tried the suggestion by "Si" to update the file in the "BeforeBuild" event - however I still get the same wrong result with Visual Studio 2008/SP1.

UPDATE/WORKAROUND: MS has responded to the bug report. As a workaround you can add

<UseHostCompilerIfAvailable>FALSE</UseHostCompilerIfAvailable> 

to your csproj file.

like image 85
laktak Avatar answered Oct 18 '22 18:10

laktak


+1 for the <UseHostCompilerIfAvailable>FALSE</UseHostCompilerIfAvailable> trick, although neither the accepted solution nor the linked article specified that the line should be added to the first <PropertyGroup> element in the .csproj file.

It is also a problem with Visual Studio only, as invoking msbuild from the command-line on the same .csproj file (without the trick) will see the generated code files compiled right away (and not the previous versions).

Also, I would like to recommend that this topic be tagged with the following, as I had to dig a lot to find it:

  1. VisualStudio
  2. compiler
  3. BeforeBuild
  4. generated
  5. .NET
  6. c#
like image 28
Olivier Dagenais Avatar answered Oct 18 '22 19:10

Olivier Dagenais