By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,264 Members | 1,100 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,264 IT Pros & Developers. It's quick & easy.

AssemblyVersionAttribute

P: n/a
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
Nov 22 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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
-------------------------------------------------------------------------------------------
J-Integra Interoperability Solutions
http://j-integra.intrinsyc.com/
high performance interop middleware for java, corba, com & .net

Nov 22 '05 #2

P: n/a
thank you,

this is exactly what i need
Pascal
"Adam Cooper" <ad*********@gmail.com> a écrit dans le message de news:
11**********************@g49g2000cwa.googlegroups. com...
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
-------------------------------------------------------------------------------------------
J-Integra Interoperability Solutions
http://j-integra.intrinsyc.com/
high performance interop middleware for java, corba, com & .net

Nov 23 '05 #3

P: n/a
Pascal Cloup wrote:
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
--
http://www.grimes.demon.co.uk/workshops/fusionWS.htm
http://www.grimes.demon.co.uk/workshops/securityWS.htm
Nov 23 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.