在将应用程序移植到 Windows 应用商店时,我注意到 .NETCore Framework 不包括:
System.Reflection.Assembly.GetExecutingAssembly()
我用它来获取版本信息以显示在菜单屏幕上。是否有替代品,或者我是否被迫将信息存储在其他地方以供检索?
EDIT:
我还发现我可以从中提取版本号typeof(MyType).AssemblyQualifiedName
但这似乎很糟糕。
我正在使用这个:
public string GetApplicationVersion()
{
var ver = Windows.ApplicationModel.Package.Current.Id.Version;
return ver.Major.ToString() + "." + ver.Minor.ToString() + "." + ver.Build.ToString() + "." + ver.Revision.ToString();
}
如果你想要程序集版本,你可以从 Version 属性中获取它:
public string GetAssemblyVersion(Assembly asm)
{
var attr = CustomAttributeExtensions.GetCustomAttribute<AssemblyFileVersionAttribute>(asm);
if (attr != null)
return attr.Version;
else
return "";
}
例如使用主应用程序的程序集:
Assembly appAsm = typeof(App).GetTypeInfo().Assembly;
string assemblyVersion = GetAssemblyVersion(appAsm);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)