473,587 Members | 2,533 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 8075
"Matthew Smith" <ma*****@macxxx .com> wrote in message news:ma******** *************** ****@msnews.mic rosoft.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: AssemblyVersion Attribute)
like this,

using System.Reflecti on;
// . . .
Assembly assy = Assembly.GetExe cutingAssembly( );
AssemblyVersion Attribute[] versionAttrs = (AssemblyVersio nAttribute[ ])
assy.GetCustomA ttributes( typeof( AssemblyVersion Attribute), false);
if ( versionAttrs != null && 0 < versionAttrs.Le ngth ) {
Console.WriteLi ne( "Assembly version is {0}.", versionAttrs[ i].Version);
}

GetCustomAttrib utes( ) 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.mic rosoft.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: AssemblyVersion Attribute)
like this,

using System.Reflecti on;
// . . .
Assembly assy = Assembly.GetExe cutingAssembly( );
AssemblyVersion Attribute[] versionAttrs = (AssemblyVersio nAttribute[ ])
assy.GetCustomA ttributes( typeof( AssemblyVersion Attribute),
false);
if ( versionAttrs != null && 0 < versionAttrs.Le ngth ) {
Console.WriteLi ne( "Assembly version is {0}.", versionAttrs[
i].Version);
}

GetCustomAttrib utes( ) 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. GetCustomAttrib ute is not in the Compact Framework. Might just go
back to what I had originally, hard-coded value in C#.
Nov 16 '05 #3
GetCustomAttri butes( ) works for any Attribute


Except pseudo custom attributes such as AssemblyVersion Attribute. 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.GetExe cutingAssembly( ).GetName().Ver sion.ToString() ;

Adam
Nov 16 '05 #5

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

Similar topics

5
36415
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 System.Reflection; using System.Runtime.CompilerServices;
2
1194
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
1979
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? Thank you in advance for any help.
2
2778
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 with the quick starts with what looks like to be a short cut to a file in each project... is there any way to have the assembly as the actuall file...
2
1660
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 appeared in the file property
2
4321
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; AssemblyProductAttribute^ apAttr = dynamic_cast<AssemblyProductAttribute^>(Attribute::GetCustomAttribute(assy,
0
1104
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 that no versioning etc are getting applied system-wide. What do I have to do to get the below stamped into all of the DLLs that make up my...
0
1342
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 info the file is no longer up-to-date with our CVS-repository. Also if I check the file in to the CVS-repository the assembly info is no longer...
2
2112
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 are failed. My main purpose is the version number stored in AssemblyInfo.vb. Thanks for your attention and kindly advice! Regards,
0
7923
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8349
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7974
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8221
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5719
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5395
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3845
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3882
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2364
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.