我正在研究一个程序,我正在尝试显示程序集FILE版本
public static string Version { get { Assembly asm = Assembly.GetExecutingAssembly(); FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(asm.Location); return String.Format("{0}.{1}", fvi.FileMajorPart, fvi.FileMinorPart); } }
目前,这只返回"AssemblyVersion"中的前两个版本号,而不是"AssemblyFileVersion".我真的很想引用AssemblyFileVersion,而不是存储一个名为"Version"的内部变量,我必须更新它和程序集版本......
[assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyFileVersion("3.5.0")]
那是AssemblyInfo.cs中的AssemblyFileVersion.我想引用"3.5.x"部分,而不是"1.0.*":/
谢谢,扎克
使用ProductMajorPart/ProductMinorPart而不是FileMajorPart/FileMinorPart:
public static string Version { get { Assembly asm = Assembly.GetExecutingAssembly(); FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(asm.Location); return String.Format("{0}.{1}", fvi.ProductMajorPart, fvi.ProductMinorPart); } }
using System.Reflection; using System.IO; FileVersionInfo fv = System.Diagnostics.FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location); Console.WriteLine("AssemblyVersion : {0}", Assembly.GetExecutingAssembly().GetName().Version.ToString()); Console.WriteLine ("AssemblyFileVersion : {0}" , fv.FileVersion.ToString ());