C#中获取版本号的方法
2009-09-08 09:43
197 查看
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、
// 有关程序集的常规信息是通过下列
// 属性集控制的。更改这些属性值可修改与程序集
// 关联的信息。
//
[assembly: AssemblyTitle("")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
修改AssemblyInfo.cs文件的上述信息
在程序中调用如下:
Version ApplicationVersion = new Version(Application.ProductVersion);
string ss = ApplicationVersion.Major;//获取主版本号
3、
我认为比较好的做法
private void GetEdition()
{
Assembly assembly = Assembly.GetExecutingAssembly();
//this.labelEdition.Text = assembly.FullName;
// 获取程序集元数据
AssemblyCopyrightAttribute copyright = (AssemblyCopyrightAttribute)
AssemblyCopyrightAttribute.GetCustomAttribute(Assembly.GetExecutingAssembly(),
typeof(AssemblyCopyrightAttribute));
AssemblyDescriptionAttribute description = (AssemblyDescriptionAttribute)
AssemblyDescriptionAttribute.GetCustomAttribute(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、
使用反射
string path = @"C:/WINNT/Microsoft.NET/Framework/v1.1.4322/System.dll";
Assembly assembly = Assembly.LoadFile(path);
AssemblyName 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);
只要得到Assembly ,剩下的都好说,
楼主可以看看Assembly的几个静态方法,应该可以满足所有需要了
比如
//得到Mscorlib.dll
Assembly.GetAssembly(typeof(string))
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、
// 有关程序集的常规信息是通过下列
// 属性集控制的。更改这些属性值可修改与程序集
// 关联的信息。
//
[assembly: AssemblyTitle("")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
修改AssemblyInfo.cs文件的上述信息
在程序中调用如下:
Version ApplicationVersion = new Version(Application.ProductVersion);
string ss = ApplicationVersion.Major;//获取主版本号
3、
我认为比较好的做法
private void GetEdition()
{
Assembly assembly = Assembly.GetExecutingAssembly();
//this.labelEdition.Text = assembly.FullName;
// 获取程序集元数据
AssemblyCopyrightAttribute copyright = (AssemblyCopyrightAttribute)
AssemblyCopyrightAttribute.GetCustomAttribute(Assembly.GetExecutingAssembly(),
typeof(AssemblyCopyrightAttribute));
AssemblyDescriptionAttribute description = (AssemblyDescriptionAttribute)
AssemblyDescriptionAttribute.GetCustomAttribute(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、
使用反射
string path = @"C:/WINNT/Microsoft.NET/Framework/v1.1.4322/System.dll";
Assembly assembly = Assembly.LoadFile(path);
AssemblyName 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);
只要得到Assembly ,剩下的都好说,
楼主可以看看Assembly的几个静态方法,应该可以满足所有需要了
比如
//得到Mscorlib.dll
Assembly.GetAssembly(typeof(string))
相关文章推荐
- C#中获取版本号的方法
- C#中获取程序集版本号的方法
- C#中获取版本号的方法
- C#中获取版本号的方法
- C#中获取版本号的方法
- C#中获取程序集版本号的方法
- 获取DLL文件版本号的三种方法
- Python获取DLL和EXE文件版本号的方法
- js获取、比较浏览器名称和版本号的简便方法
- Android编程实现应用获取包名、版本号、权限等信息的方法
- 安卓中获取应用程序版本号和版本名称的方法
- win10 系统版本号获取的三种方法
- python中获取python版本号的方法
- iOS获取当前版本号 Bundle ID等信息的方法
- symbian下系统版本号与手机型号的获取方法
- JS获取当前使用的浏览器名字以及版本号实现方法
- 获取浏览器版本号的方法
- iOS获取当前版本号 Bundle Id等信息的方法
- jquery获取浏览器类型和版本号的方法
- jquery获取浏览器类型和版本号方法