Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
534 views
in Technique[技术] by (71.8m points)

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

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

C:WINDOWSMicrosoft.NETFrameworkv3.5MSBuild.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)PropertiesAssemblyInfo.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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...