C#中获取程序集版本号的方法
时间:2013年08月16日作者:小侃评论次数:0
方法零:string version = Assembly.GetExecutingAssembly().GetName().Version.ToString();
方法一:
public void GetFileVersion() {
FileVersionInfo myFileVersionInfo = FileVersionInfo.GetVersionInfo(Path路径字符串);
string AssmblyVersion=myFileVersionInfo.FileVersion;
}
FileVersionInfo myFileVersionInfo = FileVersionInfo.GetVersionInfo(Path路径字符串);
string AssmblyVersion=myFileVersionInfo.FileVersion;
}
方法二:
[assembly: AssemblyTitle(“”)]
[assembly: AssemblyDescription(“”)]
[assembly: AssemblyConfiguration(“”)]
[assembly: AssemblyCompany(“”)]
[assembly: AssemblyProduct(“”)]
[assembly: AssemblyCopyright(“”)]
[assembly: AssemblyTrademark(“”)]
[assembly: AssemblyCulture(“”)]
修改AssemblyInfo.cs文件的上述信息
[assembly: AssemblyDescription(“”)]
[assembly: AssemblyConfiguration(“”)]
[assembly: AssemblyCompany(“”)]
[assembly: AssemblyProduct(“”)]
[assembly: AssemblyCopyright(“”)]
[assembly: AssemblyTrademark(“”)]
[assembly: AssemblyCulture(“”)]
修改AssemblyInfo.cs文件的上述信息
在程序中调用如下:
Version ApplicationVersion = new Version(Application.ProductVersion);
string AssmblyVersion = ApplicationVersion.Major;//获取主版本号
Version ApplicationVersion = new Version(Application.ProductVersion);
string AssmblyVersion = ApplicationVersion.Major;//获取主版本号
方法三:
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));
{
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));
string a = description.Description;
string b = description.Description;
string c = copyright.Copyright;
string d = Application.ProductVersion;
}
方法四:
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);
string a=version.Major.ToString();
string b= version.Minor.ToString();
string c=version.Revision.ToString();
string d=version.Build.ToString();
最新评论
Does your site have a contact pa »
Post:2015-05-25 23:19:39请问你tag,云图的动画效果是怎么实现的?
Post:2015-04-23 16:16:47很强大!
Post:2012-03-17 23:03:43老师 您好,我想向您咨询一下,我 »
Post:2012-03-17 19:00:43电脑菜鸟一个搜黑客,就来到这里了 »
Post:2012-03-04 14:23:16我的为什么说无法保存到此处,请选 »
Post:2012-02-15 23:21:07小侃帅哥,姐姐来看你了。文章不错 »
Post:2011-12-18 18:26:03:!: :mrgreen:
Post:2011-09-05 16:53:36