Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to display/manipulate program version number

Status
Not open for further replies.

cmdematos

IS-IT--Management
Mar 7, 2001
29
US
How do I display and manipulate a c# program version number? I think I have the display part, but how do I set the version number from version 1 to version 2?
 
I'm not sure you can programmatically retrive or modify the version number. There is an Assembly class in the System.Reflection namespace which allows you to access the current asembly. You can load in an assembly from within a class using the static GetAssembly method like this
Code:
Type type = this.GetType();
Assembly assembly = Assembly.GetAssembly(type);
However, I don't think it has a version number property :-( though you can modify the version number of the assembly declaritively from within the Assembly.info file in your project root before compilation.

Rob

Every gun that is made, every warship launched, every rocket fired, signifies in the final sense a theft from those who hunger and are not fed, those who are cold and are not clothed - Eisenhower 1953
 
You can control the version of an Assembly (.EXE or .DLL) using [assembly: AssemblyVersion("x.x.x.x")]
that you find in the AssemblyInfo.cs file.
//
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
At run time, you can only retrieve that version for the executing assembly like here:
Code:
string vs = Application.ProductVersion;
or using  FileVersionInfo or System.Version class
[code]
 FileVersionInfo fvi = FileVersionInfo.GetVersionInfo("my.dll");
 Console.WriteLine("File: " + fvi.FileDescription + '\n' +"Version: " + fvi.FileVersion;
You can control the version from the config file by adding something like that:
<version>
<add key="title" value="MyApp [BETA]"/>
<add key="release" value="0.2.3"/>
</version>
The version could be controlled at assembly level, class level, method level by impleneting an Attribute class, let say AttributeVersion, derived from Attribute class.
Using System.Version class and this custom class you can manage the vesrions over your projects/applications.
-obislavu-
 
You can also access it for the current assembly like this:
Code:
Assembly myAssembly = Assembly.GetExecutingAssembly();
AssemblyName myAssemblyName = myAssembly.GetName();
Version myVersion = myAssemblyName.Version();
Console.WriteLine("{0}.{1}.{2}.{3}", myVersion.Major.ToString(), myVersion.Minor.ToString(), myVersion.Build.ToString(), myVersion.Revision.ToString());

Chip H.



____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top