473,614 Members | 2,076 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Retrieve version information

I'm trying to put together a class that retrieves version information from
my assembly and am having a problem. The code below happily retrieves the
AssemblyTitle and AssemblyDescrip tion but fails to retrieve the Version
number. Both of these are specified in the AssemblyInfo.cs file, so I can't
see why I can't get the version umber. Any suggestions?

Thanks
Steve

using System;
using System.Collecti ons.Generic;
using System.Text;
using System.Reflecti on;

namespace Lucidus.IPM.IPM
{
class VersionInformat ion
{
public static string ProductDescript ion()
{
Assembly currentAssembly = Assembly.GetExe cutingAssembly( );
Type attrType = typeof(Assembly DescriptionAttr ibute);

object[] attrs = currentAssembly .GetCustomAttri butes(attrType,
false);
if (attrs.Length 0)
{
AssemblyDescrip tionAttribute desc =
(AssemblyDescri ptionAttribute) attrs[0];
return desc.Descriptio n;
}
else
{
return "";
}
}

public static string ProductVersion( )
{
Assembly currentAssembly = Assembly.GetExe cutingAssembly( );
Type attrType = typeof(Assembly VersionAttribut e);

// *************** ********Always fails to get version
object[] attrs = currentAssembly .GetCustomAttri butes(attrType,
false);
if (attrs.Length 0)
{
AssemblyVersion Attribute desc =
(AssemblyVersio nAttribute)attr s[0];
return desc.Version;
}
else
{
return "0.0";
}
}

public static string ProductName()
{
Assembly currentAssembly = Assembly.GetExe cutingAssembly( );
Type attrType = typeof(Assembly ProductAttribut e);

object[] attrs = currentAssembly .GetCustomAttri butes(attrType,
false);
if (attrs.Length 0)
{
AssemblyProduct Attribute desc =
(AssemblyProduc tAttribute)attr s[0];
return desc.Product;
}
else
{
return "";
}
}

public static string ProductTitle()
{
Assembly currentAssembly = Assembly.GetExe cutingAssembly( );
Type attrType = typeof(Assembly TitleAttribute) ;

object[] attrs = currentAssembly .GetCustomAttri butes(attrType,
false);
if (attrs.Length 0)
{
AssemblyTitleAt tribute desc =
(AssemblyTitleA ttribute)attrs[0];
return desc.Title;
}
else
{
return "";
}
}

public static string ProductId()
{
Assembly currentAssembly = Assembly.GetExe cutingAssembly( );
string prodId = ProductTitle() + " Version " + ProductVersion( );

System.Windows. Forms.MessageBo x.Show(prodId);

return prodId;
}

}
}

Aug 24 '06 #1
2 3836
Steve Barnett wrote:
I'm trying to put together a class that retrieves version information from
my assembly and am having a problem. The code below happily retrieves the
AssemblyTitle and AssemblyDescrip tion but fails to retrieve the Version
number. Both of these are specified in the AssemblyInfo.cs file, so I can't
see why I can't get the version umber. Any suggestions?
A long time ago, somewhere deep within the msdn docs, I read that the
AssemblyVersion Attribute is some kind of special attribute that you
cannot retrieve like other attributes. You have to use something like that:

public string ProductVersion( ) {
return Assembly.GetExe cutingAssembly( ).GetName().Ver sion.ToString() ;
}

... haven't tested it, but should work. As far as I know, that's the
easiest way to get at the version information specified in the
AssemblyVersion "Attribute" .

hth,
Max
Aug 24 '06 #2
Just when I thought I was starting to get a handle on this stuff, they go
and throw me a curve-ball like this.

Worked perfectly, thanks.

Steve

"Markus Stoeger" <sp******@gmx.a twrote in message
news:u2******** ******@TK2MSFTN GP04.phx.gbl...
Steve Barnett wrote:
>I'm trying to put together a class that retrieves version information
from my assembly and am having a problem. The code below happily
retrieves the AssemblyTitle and AssemblyDescrip tion but fails to retrieve
the Version number. Both of these are specified in the AssemblyInfo.cs
file, so I can't see why I can't get the version umber. Any suggestions?

A long time ago, somewhere deep within the msdn docs, I read that the
AssemblyVersion Attribute is some kind of special attribute that you cannot
retrieve like other attributes. You have to use something like that:

public string ProductVersion( ) {
return Assembly.GetExe cutingAssembly( ).GetName().Ver sion.ToString() ;
}

.. haven't tested it, but should work. As far as I know, that's the
easiest way to get at the version information specified in the
AssemblyVersion "Attribute" .

hth,
Max

Aug 25 '06 #3

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

Similar topics

0
2080
by: Miki | last post by:
Hi. I have a IIS server with php3 installed. I have SQL server database and data stored in unicode format (nvarchar fields). In header of my php I have the meta: <meta HTTP-EQUIV="content-type" CONTENT="text/html; charset=UTF-8">. I have the following problem: - I trie to do a query using ODBC (version 3.525.1022.0) and SQL
5
11187
by: David Rasmussen | last post by:
Some sites seem to be session driven in the sense that if I visit the homepage and do a few clicks I can navigate anywhere I want, but if I paste the current location into a new browser window after having navigated to some page, it doesn't work. It just returns to the start page or says "timeout" etc. This means that I can't read these pages from PHP with $string = file_get_contents('http://some.url/blah/deep/link');
79
14044
by: Klaus Bonadt | last post by:
In order to protect software from being copied without licence, I would like to use something like a key, which fits only to the current system. The serial number of the CPU or the current operating system would be appropriate. However, I do not know how to retrieve the information. Could you help? Klaus
1
3067
by: Eddy Fuchs | last post by:
Hi folks, I'm searching on this issue since a couple of days: How do I programmatically retrieve the version of an installed program? Is there a possibility to retrieve it via the local MSI database? Or do I have an other chance to get to this information? I need to retrieve it because I do have to check if an update of my app is necessary. But therefore I need to know what Version currently is installed.
5
2924
by: Roy Gourgi | last post by:
Hi, I am used to working in Visual FoxPro and I would like to be able to create a database and store and retrieve information from it. What is the simplest way to do it and what should I be using as there are many choices to choose from. My database will contain a lot of records. TIA
2
1389
by: shantanu | last post by:
Dear All I need to do a implementation in c#. The requirement is like i have to retrieve the information of the installer , like version and compare it with the version of the new installer.How can do the same in c# Kindly assist Regards shantanu
1
1464
by: Jona | last post by:
Hello, This might be easy but I have no clue how too.... I'm currently writting a program in Microsoft Visual C++ and a file in the .rc called (_VERSION_INFO - Version) keeps my programs information nice and neat... :p like the programs version.... I want to know how I can retrieve my programs version information from there... so I can display that to the user..? Like an About option were it goes and get this information....
2
3966
by: Dedalus | last post by:
If I want to retrieve a full version information for an ms access databases, I use (from vb6 code) the "Access.Application" object and SysCmd method. Whit the number returned by the method I can identify the service pack applied to database (e.g. ... SysCmd(acSysCmdAccessVer) = 9 -Access 2000 SysCmd(715) = 2719 ' Access 2000 No Service Pack SysCmd(715) = 3822 ' Access 2000 SP1 SysCmd(715) = 4506 ' Access 2000 SP2 SysCmd(715) = 6620 '...
12
77976
lifeisgreat20009
by: lifeisgreat20009 | last post by:
I am a newbie to Struts and JSP...I have been working on the code below for 5 hours now..I googled a lot but couldn't get much help so finally I am here.. Hoping of getting my problem solved. Please give me some idea where I am going wrong ?? I just want to retrieve data from my emp_mstr table and display it using my JSP file... The table emp_mstr is as follows :- CREATE TABLE EMP_MSTR( EMP_NO VARCHAR(10) PRIMARY KEY, PASSWORD...
0
8182
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8627
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8579
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7093
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6088
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4052
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4127
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1747
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1425
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.