views:

102

answers:

5

We have a nightly build process that automatically versions all C++ projecs. Here's how it works. There's a common header file VersionNumber.h that has a specific #define for the version number. The nighly build checks this file out, increments the integer behind that #define and checks it in. All Visual C++ projects #include that header into their resource files and use that define for specifying the version (version is smth like 1.0.3.ThatNumber).

So far so good. Now I'd like to have the same for the C# class libraries built in the same daily build. Currently they all have

[assembly: AssemblyVersion("1.0.*")]

in the AssemblyInfo.cs files and libraries end up with 1.0.HorribleNumber.AnotherHorribleNumber as the version and the two numbers don't correlate to the number used by C++ projects.

How do I have the same determenistic automatic version numbering in my C# projects with minimal effort?

A: 

Hi,

here or here (artiso) you can find a solution.

K.Hoffmann
+1  A: 

You can do something like you already do for your C++ technique, but search for the "assembly: AssemblyVersion( string and replace the number in quotes with the full, required version number.

In C# the wildcard on the version number tells the compiler to automatically update the version number -- if there's no wildcard, it will just use the full number supplied.

e.g.

[assembly: AssemblyVersion("1.0.3.10")]

Will always use that version number until you change it in the file.

Dr Herbie
+1  A: 

We use FinalBuilder for automated builds (we have TeamCity call it), and it does this sort of stuff automatically (i.e. it can get a build number from somewhere else (ini file, environment variable, command line, whatever) and then update all the assembly versions for you with the build number.)

Obviously not the only way to do it, but if you haven't used something like FinalBuilder, then give it a try - our experience is you start to wonder why you previously spent so long being clever with Makefiles and batch files...

But if you don't want to do that, can you get the same process which generates/modifies the VersionNumber.h file to also spit out VersionNumber.cs, with an AssemblyVersion line in it? Then you can just include that file in your project.

The AssemblyVersion directive doesn't need to be in the same file as all the rest of your AssemblyInfo stuff.

Will Dean
A: 

You can set assembly version from another file, by adding a link to it. A similar solution is

link text

Boris Modylevsky
+3  A: 

Firstly you can specify the full version as follows:

[assembly: AssemblyVersion("1.0.9.10")]

Secondly, a common approach to make this a little more straightforward (and echoes your C++ approach) is to have a single Version.cs file (name unimportant) that sits in a common location that has the version attributes in it. You can then add this file as a link to all your cs projects, remembering to remove the version attributes from your AssemblyInfo.cs files. In this way you only have a single file to update (before running your build). You can also put other common assembly attributes in your Version.cs file such as: NeutralResourcesLanguage or CLSCompliant.

If you do not use a single "Version.cs" approach, then you can work recursively through your source code directory structure, and update AssemblyInfo files individually (before running your build).

It may not be relevant to you, but the version numbers (in AssemblyVersion) have a maximum range of 16bit. I have seen this become an issue where dates have been used for these numbers. If you wish to have more latitude then AssemblyFileVersion does not have these restriction, but is purely for informational purposes only in .Net, rather than part of the assembly's identity. It is common to set AssemblyVersion and AssemblyFileVersion to the same values as some tools display combinations of these.

See the following for more on AssemblyVersion vs AssemblyFileVersion:

http://stackoverflow.com/questions/64602/what-are-differences-between-assemblyversion-assemblyfileversion-and-assemblyinf

chibacity