19.2 Setting the Assembly Version

 <  Day Day Up  >  

You want to have the compiler set the version of an emitted assembly.


Technique

The technique here is almost identical to that for setting the informational assembly attributes because the assembly version is controlled by an attribute, AssemblyVersionAttribute . You can find this attribute in the AssemblyInfo.cs file of VS.NET-generated projects or which you can add yourself:

 
 [assembly: AssemblyVersion("1.0.1.12")] 

This line causes the compiled assembly to have version 1.0.1.12. (major version 1, minor version 0, build 1, revision 12).

If you omit this attribute entirely, the C# compiler gives the assembly the version 0.0.0.0 .

One useful point about this particular attribute is that the compiler accepts wildcards in the version number. Wildcards cause the compiler to automatically generate part of the version for you. The possible forms you can supply are

 
 <n> <n>.<n> <n>.<n>.* <n>.<n>.<n> <n>.<n>.<n>.* <n>.<n>.<n>.<n> 

Here, <n> indicates any positive integer. If you omit part of the version, the compiler sets the relevant version numbers to zero, but * asks the compiler to generate the rest of the version automatically. For example, the following line results in an assembly version of 3.5.0.0 :

 
 [assembly: AssemblyVersion("3.5")] 

The following line results in the build and revision numbers being generated automatically:

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

For example, we compiled a program with that setting and got an assembly version of 3.5.1281.31179 . According to the documentation, the compiler calculates the build number as the number of days since 1 January 2000 and the revision number as half of the number of seconds since yesterday at midnight. However, there's little point ascribing any significance to the actual number. (Besides, our own tests appear to show a bug in the revision number that ignores Daylight Savings Time.) The real significance is that every time you do a new build of your project, the build and revision numbers increase ”which can be useful if it's important that successive builds don't have the same version.

Comments

You need to supply the assembly version in the correct format: the different parts of the version number are separated by dots, in contrast to the ILDasm format, which separates them with colons (as in 1:0:1:12 ). Fortunately, if you use the wrong format in your C# code, you get a compilation error, which makes the problem easy to correct.

 <  Day Day Up  >  


Microsoft Visual C# .Net 2003
Microsoft Visual C *. NET 2003 development skills Daquan
ISBN: 7508427505
EAN: 2147483647
Year: 2003
Pages: 440

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net