473,395 Members | 1,974 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

AssemblyInfo.cs AssemblyVersion

Is there a way to get the value that is stored in the AssemblyVersion
attribute that's in AssemblyInfo.cs?
Nov 16 '05 #1
4 8065
"Matthew Smith" <ma*****@macxxx.com> wrote in message news:ma***************************@msnews.microsof t.com...
Is there a way to get the value that is stored in the AssemblyVersion
attribute that's in AssemblyInfo.cs?


Yes, you can get a reference to the currently executing assembly and
then get it's custom attributes (filtering by type: AssemblyVersionAttribute)
like this,

using System.Reflection;
// . . .
Assembly assy = Assembly.GetExecutingAssembly( );
AssemblyVersionAttribute[] versionAttrs = (AssemblyVersionAttribute[ ])
assy.GetCustomAttributes( typeof( AssemblyVersionAttribute), false);
if ( versionAttrs != null && 0 < versionAttrs.Length ) {
Console.WriteLine( "Assembly version is {0}.", versionAttrs[ i].Version);
}

GetCustomAttributes( ) works for any Attribute but it returns an array of
plain object references, so don't forget to typecast it to the appropriate
Type of Attribute. If you pass the Type as the argument then you can be
guaranteed that the typecast is valid.
Derek Harmon
Nov 16 '05 #2
In article <#e*************@TK2MSFTNGP15.phx.gbl>,
"Derek Harmon" <lo*******@msn.com> wrote:
"Matthew Smith" <ma*****@macxxx.com> wrote in message
news:ma***************************@msnews.microsof t.com...
Is there a way to get the value that is stored in the AssemblyVersion
attribute that's in AssemblyInfo.cs?


Yes, you can get a reference to the currently executing assembly and
then get it's custom attributes (filtering by type: AssemblyVersionAttribute)
like this,

using System.Reflection;
// . . .
Assembly assy = Assembly.GetExecutingAssembly( );
AssemblyVersionAttribute[] versionAttrs = (AssemblyVersionAttribute[ ])
assy.GetCustomAttributes( typeof( AssemblyVersionAttribute),
false);
if ( versionAttrs != null && 0 < versionAttrs.Length ) {
Console.WriteLine( "Assembly version is {0}.", versionAttrs[
i].Version);
}

GetCustomAttributes( ) works for any Attribute but it returns an array of
plain object references, so don't forget to typecast it to the appropriate
Type of Attribute. If you pass the Type as the argument then you can be
guaranteed that the typecast is valid.


Of course I left off the qualifying phrase: "in .Net Compact Framework".
Grrr. GetCustomAttribute is not in the Compact Framework. Might just go
back to what I had originally, hard-coded value in C#.
Nov 16 '05 #3
GetCustomAttributes( ) works for any Attribute


Except pseudo custom attributes such as AssemblyVersionAttribute. To
get the version you use assy.GetName().Version.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 16 '05 #4
Or a slightly simpler way:

string version = Assembly.GetExecutingAssembly().GetName().Version. ToString();

Adam
Nov 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: c8prog | last post by:
I'm using dotnetframework 1.1. By the way, I don't know how to read the information of AssemblyInfo.cs file. I wish to read it. The following Example Files. File 1: AssemblyInfo.cs using...
2
by: C | last post by:
Hi, I have a project with a number of assembly's. (a) How do I version these assembly's? (b) Is there an option to get the compiler to set the version in the Assembly.info file? Thanks,
2
by: Rob | last post by:
What VB run-time methods are available to retrieve information (such as AssemblyCopyright, AssemblyProduct, AssemblyVersion, etc.) from the AssemblyInfo.vb file for the current executable? ...
2
by: Brian Henry | last post by:
is there any way to make an assembly file accessable across multiple projects (we have over 20 that need the info all to be the same at build version, title, desc, copyright,etc) i saw MS did this...
2
by: Eddie | last post by:
Hello, there. When I create new 'VC++ -> CLR -> Windows Form Application' project, there created AssemblyInfo.cpp file. There exists strings like ; I believe this information should be...
2
by: Eddie | last post by:
I tried a few more thing. I found that I can access the AssemblyInfo.cpp like follows.(This is from the VS help system.) Type^ clsType = Form1::typeid; Assembly^ assy = clsType->Assembly; ...
0
by: xenophon | last post by:
In my 1.1 ASP.NET project, AssemblyInfo.cs had custom information about versioning and etc. With 2.0, I made an AssemblyInfo.cs in the root of my site, but with all of the multiple DLLs it appears...
0
by: per9000 | last post by:
Hi all, we use CVS to manage versions of our code. Since the CVS keeps track of everything we need I want to synchronize the assembly info with CVS. The problem is that if I update the assembly...
2
by: James Wong | last post by:
Hi everybody, I would like to know how to retrieve information from AssemblyInfo.vb inside web service. I've tried many different ways including GetExecutingAssembly or similar method but all...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.