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.