How to obtain the version number in C #

Source: Internet
Author: User

Reprinted from: http://www.cnblogs.com/gavincome/archive/2007/12/15/995665.html

 

1,
Public void getfileversion (){
// Get the file version for the notepad.
Fileversioninfo myfileversioninfo = fileversioninfo. getversioninfo ("% SystemRoot % // notepad.exe ");

// Print the file name and version number.
Textbox1.text = "file:" + myfileversioninfo. filedescription + '/N' +
"Version number:" + myfileversioninfo. fileversion;
}

2,
// The general information about the Assembly is as follows:
// Attribute set control. Changing these property values can be modified with the Assembly
// Associated information.
//
[Assembly: assemblytitle ("")]
[Assembly: assemblydescription ("")]
[Assembly: assemblyconfiguration ("")]
[Assembly: assemblycompany ("")]
[Assembly: assemblyproduct ("")]
[Assembly: assemblycopyright ("")]
[Assembly: assemblytrademark ("")]
[Assembly: assemblyculture ("")]

Modify the preceding information of the assemblyinfo. CS file.

The following code is called in a program:
Version applicationversion = new version (application. productversion );
String Ss = applicationversion. Major; // obtain the main version number.

3,
I think it is a good practice.
Private void getedition ()
{
Assembly = assembly. getexecutingassembly ();
// This. labeledition. Text = assembly. fullname;

// Obtain Assembly metadata
Assemblycopyrightattribute copyright = (assemblycopyrightattribute)
Assemblycopyrightattribute. getcustomattribute (assembly. getexecutingassembly (),
Typeof (assemblycopyrightattribute ));
Assemblydescriptionattribute description = (assemblydescriptionattribute)
Assemblydescriptionattribute. getcustomattriction (system. reflection. Assembly. getexecutingassembly (),
Typeof (assemblydescriptionattribute ));

This. labelappname. Text = description. description;
// This. labeledition. Text = description. description;
// This. labeledition. Text = copyright. copyright;
This. labeledition. Text = application. productversion;
}

4,
Use reflection

String Path = @ "C:/winnt/Microsoft. NET/framework/v1.1.4322/system. dll ";
Assembly = assembly. LoadFile (PATH );
Assemblyname = assembly. getname ();
Version version = assemblyname. version;
Console. writeline (assemblyname. fullname );
Console. writeline ("major version =" + version. Major );
Console. writeline ("minor version =" + version. Minor );
Console. writeline ("revision version =" + version. Revision );
Console. writeline ("build version =" + version. Build );

As long as you get the assembly, the rest is easy to say,
The main author can look at several static methods of assembly, it should be able to meet all the needs
For example
// Obtain mscorlib. dll.
Assembly. getassembly (typeof (string ))

 

------------------------------------------------------------------------

 

Note: The 3rd methods are the most common and. netcf35 is also available.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.