如何从库中的窗口8和8.1应用程序中获取应用程序名称?
-
20-12-2019 - |
题
我有2个名为“Sample”(Store App)和“SampleLib”(商店库)的项目。当我从sample.csproj调用它时,我想获取正在运行的应用程序的名称。
我想基于它的操作系统版本是:
在8.0:
// Get the assembly with Reflection:
Assembly assembly = typeof(App).GetTypeInfo().Assembly;
// Get the custom attribute informations:
var titleAttribute = assembly.CustomAttributes.Where(ca => ca.AttributeType == typeof(AssemblyTitleAttribute)).FirstOrDefault();
// Now get the string value contained in the constructor:
return titleAttribute.ConstructorArguments[0].Value.ToString();
.
在8.1:
Windows.ApplicationModel.Package.Current.DisplayName
.
但是当我将目标框架设置为8.0时,我可以在lib项目上设置目标框架吗?
解决方案
您可以创建两个项目,一个为8个,一个为8.1,并定义自定义编译器常量,该常量将根据您为该值设置的内容而定性编译。
不隶属于 StackOverflow