日志标签:版本号

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

时间:2013年08月16日作者:小侃评论次数:0

方法零: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();

.Net 中如何比较两个版本号的大小

时间:2013年08月16日作者:小侃评论次数:0

今天遇到这个问题,记录一下。

要自己写是个比较麻烦的事,.Net系统提供了Version类来解决这个问题。使用示范:

use System.Version:

string s1 ="001.001.002.003", s2 = "001.001.001.001";
Version v1 = new Version(s1), v2 = new Version(s2);
if (v1 > v2)
MessageBox.Show("Yes");

 

参考MSDN: http://msdn.microsoft.com/en-us/library/system.version.aspx