AssemblyVersionAttribute

  • Thread starter Thread starter Pascal Cloup
  • Start date Start date
P

Pascal Cloup

Hi,

I could not get the AssemblyVersion attribute. I use the following code:

public static string GetProductVersion()

{

Assembly appAssembly = Assembly.GetExecutingAssembly();

Object[] cma;

cma = appAssembly.GetCustomAttributes( typeof(AssemblyVersionAttribute) ,
true );

return( ((AssemblyVersionAttribute)(cma[0])).InformationalVersion );

}

The same kind of code works with other attributes (AssemblyTitle,
AssemblyProduct,...). Someone can help?

thanks in advance,
Pascal
 
If you are just looking for Assembly Version number, you can get it
using this code snippet..

Assembly.GetExecutingAssembly().GetName().Version.ToString()

Cheers,

Adam Cooper
 
Pascal said:
I could not get the AssemblyVersion attribute. I use the following
code:
cma = appAssembly.GetCustomAttributes(
typeof(AssemblyVersionAttribute) , true );

The assembly version is NOT a custom attribute. Unfortunately, the C#
syntax confuses the issue. [AssemblyVersion] is a message to the
compiler to tell the compiler to set the version metadata of the
assembly to the specified value. As Adam pointed out, you get the
version through the name of the assembly, not through a custom
attribute.

C# is quite sloppy in this respect. For example [AssemblyKeyFile] is a
message to the compiler to use a specific key file to sign the assembly
and create the public key token for the strong name. The path and name
of the key file is of no use at all to the runtime, nor to anyone else,
but the C# compiler will add a custom attribute (.custom metadata) for
the key file in your assembly! This is totally unnecessary and it leaks
possibly personal information (do you want your customers to know the
name of your build folder?). In .NET 2.0 the C# compiler allows you to
use a command line switch to pass the name of the key file and so the
..custom attribute is not created. (However, code that uses
[AssemblyKeyFile] will still create the .custom metadata on .NET 2.0.)

Richard
 
Back
Top