我正在编写一个程序,并试图显示程序集文件版本
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")]这是我的AssemblyFileVersion从AssemblyInfo.cs。我只想引用"3.5.x“部分,而不是"1.0.*”:/
谢谢,扎克
发布于 2009-03-31 00:44:04
使用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);
}
}发布于 2009-12-07 10:46:41
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 ());发布于 2011-08-23 04:55:20
var fileVersion = GetCustomAttributeValue<AssemblyFileVersionAttribute>(assembly, "Version");
private static string GetCustomAttributeValue<T>(Assembly assembly, string propertyName)
where T : Attribute
{
if (assembly == null || string.IsNullOrEmpty(propertyName)) return string.Empty;
object[] attributes = assembly.GetCustomAttributes(typeof(T), false);
if (attributes.Length == 0) return string.Empty;
var attribute = attributes[0] as T;
if (attribute == null) return string.Empty;
var propertyInfo = attribute.GetType().GetProperty(propertyName);
if (propertyInfo == null) return string.Empty;
var value = propertyInfo.GetValue(attribute, null);
return value.ToString();
}https://stackoverflow.com/questions/699580
复制相似问题