• 00
  • :
  • 00
  • :
  • 00

C#中获取程序集版本号的方法

我的方法:
string version = Assembly.GetExecutingAssembly().GetName().Version.ToString();

 

 
方法一:
public void GetFileVersion() {
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文件的上述信息


在程序中调用如下:

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)); 

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(); 

 


原文链接:http://ruantnt.blog.163.com/blog/static/19052545220118932123551/

 

posted @ 2013-08-28 16:01  Garson_Zhang  阅读(1369)  评论(0编辑  收藏  举报