Search code examples
visual-studioprebuildpre-build-event

How to pick up the latest version AssemblyInfo.cs as modified by the pre-build event?


I'm currently playing around with the pre and post build events in VS2010, trying to get my SVN version number into the AssemblyInfo.cs file and hence compiled into my build dll.

In the pre-build I run a script which updates the AssemblyInfo.cs file and in my post build step I run a script to reset it to a zero.

I want to do this because if I leave the latest version, then SVN sees this as a change, which will be committed, which updates the SVN version number and hence results in another change; this gets kinda recursive.

The problem I have run into is that the build picks up the original version of the file, not the one updated by the pre-build step.

Therefore:

If (as a test) I manually set the version number in the file to:

[assembly:AssemblyVersion("1.0.0.123")]

Then the pre-build updates it to:

[assembly: AssemblyVersion("1.0.0.456")]

Then the post build updates it to:

[assembly: AssemblyVersion("1.0.0.0")]

And when I look at the dll that gets built, the version is 1.0.0.123

I have checked that pre-build step is completing before the build starts - but even if I enforce a long wait (by calling out to notepad.exe or something) VS2010 still doesn't manage to pick up the updated file.

You can see this behaviour simply by putting notepad.exe in the pre-build command - then while notepad is running; go and change the AssemblyInfo.cs file by hand. The build won't start unil you close the notepad - but once you close notepad it will then build with the original version of the file.

Am I missing something here in the way the pre-build is supposed to work? Is there any way to force the build to pick up and use the updated file?

Any clues appreciated :)


Solution

  • Turns out that leaving the computer turned off for a couple days and coming back to it fixes this issue...
    I guess a computer restart might have been enough to shake it loose. Comes back to: Have you tried turning it off and on again. sigh