Jus*_*les 13 c# reflection windows-8 windows-store-apps
在将应用程序移植到Windows应用商店时,我注意到.NETCore Framework不包括:
System.Reflection.Assembly.GetExecutingAssembly()
我用它来获取显示在菜单屏幕上的版本信息.是否有替代品或我被迫将信息存储在别处以供检索?
编辑:
我还发现我可以提取一个版本号,typeof(MyType).AssemblyQualifiedName
但这看起来很糟糕.
Ant*_*ula 25
我用这个:
public string GetApplicationVersion()
{
var ver = Windows.ApplicationModel.Package.Current.Id.Version;
return ver.Major.ToString() + "." + ver.Minor.ToString() + "." + ver.Build.ToString() + "." + ver.Revision.ToString();
}
Run Code Online (Sandbox Code Playgroud)
如果你想要汇编版本,你可以从Version属性获取它:
public string GetAssemblyVersion(Assembly asm)
{
var attr = CustomAttributeExtensions.GetCustomAttribute<AssemblyFileVersionAttribute>(asm);
if (attr != null)
return attr.Version;
else
return "";
}
Run Code Online (Sandbox Code Playgroud)
例如,使用主App的程序集:
Assembly appAsm = typeof(App).GetTypeInfo().Assembly;
string assemblyVersion = GetAssemblyVersion(appAsm);
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
7836 次 |
最近记录: |