如何在 UWP 应用程序中检查 Windows 10 OS 版本以消除 WACK 测试失败?
How to check the Windows 10 OS version in an UWP app so as to eliminate WACK test fail?
我正在开发一个 UWP 应用程序,它使用了旧版本 Windows10 中不可用的一些功能。因此,我需要检查是否安装了创意者更新。
使用 AnalyticsInfo.VersionInfo 的应用程序中有版本检查代码。然而,最新一轮的 WACK 测试给出了以下失败:
FAILED
Platform version launch
• Error Found: The high OS version validation detected the following
errors:
o Failed to stop the app AppName.group.mbb.
o The app Company.AppName_2.3.56045.0_x64__cx08jceyq9bcp failed
platform version launch test.
• Impact if not fixed: The app should not use version information to
provide functionality that is specific to the OS.
• How to fix: Please use recommended methods to check for available
functionality in the OS. See the link below for more information.
Operating System Version
我知道 this question,但如果可能的话宁愿修复失败。
我在 MSDN 上找到了有关如何制作 UWP 应用程序的建议 "version adaptive" here.
我现在有这个代码:
using Windows.Foundation.Metadata;
if (ApiInformation.IsMethodPresent("Windows.Networking.Connectivity.ConnectionProfile", "GetNetworkUsageAsync"))
{
//do stuff
}
我的Windows版本是1703 15063.483,代码其他地方使用GetNetworkUsageAsync成功。但是对 IsMethodPresent 的调用总是 returns false.
我的代码有什么问题?
以及是否有更好的功能来检查是否安装了 Creators Update?
更新:
对于上述失败,我遵循了 Microsoft 指南,并将版本检查从 AnalyticsInfo.VersionInfo 更改为 Windows.Foundation.Metadata.ApiInformation。该应用程序仍未通过 WACK 测试并出现相同的错误。
第二次更新:
将 Windows10 更新到 Creators Update,Build 16251.0 后,此错误在我的计算机上消失了。
试试这个
string deviceFamilyVersion= AnalyticsInfo.VersionInfo.DeviceFamilyVersion;
ulong version = ulong.Parse(deviceFamilyVersion);
ulong major = (version & 0xFFFF000000000000L) >> 48;
ulong minor = (version & 0x0000FFFF00000000L) >> 32;
ulong build = (version & 0x00000000FFFF0000L) >> 16;
ulong revision = (version & 0x000000000000FFFFL);
var osVersion = $"{major}.{minor}.{build}.{revision}";
来源:
也许像这样的小帮手class?请注意,调用此方法的成本可能很高,因此建议执行一次并缓存数据。
(更新:如果你使用Windows组合API,你会发现AreEffectsFast
and AreEffectsSupported
很有帮助,因为您可以使用它们根据用户的设备和 OS 条件打开和关闭效果。我扩展了下面的 class 以将它们公开为两个新属性。)
public class BuildInfo
{
private static BuildInfo _buildInfo;
private BuildInfo()
{
if (ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 5))
{
Build = Build.FallCreators;
}
else if (ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 4))
{
Build = Build.Creators;
}
else if (ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 3))
{
Build = Build.Anniversary;
}
else if (ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 2))
{
Build = Build.Threshold2;
}
else if (ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 1))
{
Build = Build.Threshold1;
}
else
{
Build = Build.Unknown;
}
if (!BeforeCreatorsUpdate)
{
var capabilities = CompositionCapabilities.GetForCurrentView();
capabilities.Changed += (s, e) => UpdateCapabilities(capabilities);
UpdateCapabilities(capabilities);
}
void UpdateCapabilities(CompositionCapabilities capabilities)
{
AreEffectsSupported = capabilities.AreEffectsSupported();
AreEffectsFast = capabilities.AreEffectsFast();
}
}
public static Build Build { get; private set; }
public static bool AreEffectsFast { get; private set; }
public static bool AreEffectsSupported { get; private set; }
public static bool BeforeCreatorsUpdate => Build < Build.Creators;
public static BuildInfo RetrieveApiInfo() => _buildInfo ?? (_buildInfo = new BuildInfo());
}
public enum Build
{
Unknown = 0,
Threshold1 = 1507, // 10240
Threshold2 = 1511, // 10586
Anniversary = 1607, // 14393 Redstone 1
Creators = 1703, // 15063 Redstone 2
FallCreators = 1709 // 16299 Redstone 3
}
要初始化 class,请在 App.xaml.cs
中的 OnWindowCreated
之后立即调用它。
protected override void OnWindowCreated(WindowCreatedEventArgs args)
{
BuildInfo.RetrieveBuildInfo();
要使用它,只需调用
if (BuildInfo.Build == Build.Anniversary) { ... }
if (BuildInfo.BeforeCreatorsUpdate) { ... }
if (BuildInfo.AreEffectsFast) { ... }
使用前先使用SystemInformation Helper by UWPCommunityToolkit. Install Microsoft.Toolkit.Uwp Nuget包。
public OSVersion OperatingSystemVersion => SystemInformation.OperatingSystemVersion;
使用它您可以获得其他系统信息,例如 DeviceModel、DeviceManufacturer 等
更多信息:SystemInformation
我正在开发一个 UWP 应用程序,它使用了旧版本 Windows10 中不可用的一些功能。因此,我需要检查是否安装了创意者更新。
使用 AnalyticsInfo.VersionInfo 的应用程序中有版本检查代码。然而,最新一轮的 WACK 测试给出了以下失败:
FAILED Platform version launch • Error Found: The high OS version validation detected the following errors:
o Failed to stop the app AppName.group.mbb.
o The app Company.AppName_2.3.56045.0_x64__cx08jceyq9bcp failed platform version launch test.
• Impact if not fixed: The app should not use version information to provide functionality that is specific to the OS.
• How to fix: Please use recommended methods to check for available functionality in the OS. See the link below for more information. Operating System Version
我知道 this question,但如果可能的话宁愿修复失败。 我在 MSDN 上找到了有关如何制作 UWP 应用程序的建议 "version adaptive" here.
我现在有这个代码:
using Windows.Foundation.Metadata;
if (ApiInformation.IsMethodPresent("Windows.Networking.Connectivity.ConnectionProfile", "GetNetworkUsageAsync"))
{
//do stuff
}
我的Windows版本是1703 15063.483,代码其他地方使用GetNetworkUsageAsync成功。但是对 IsMethodPresent 的调用总是 returns false.
我的代码有什么问题?
以及是否有更好的功能来检查是否安装了 Creators Update?
更新: 对于上述失败,我遵循了 Microsoft 指南,并将版本检查从 AnalyticsInfo.VersionInfo 更改为 Windows.Foundation.Metadata.ApiInformation。该应用程序仍未通过 WACK 测试并出现相同的错误。
第二次更新:
将 Windows10 更新到 Creators Update,Build 16251.0 后,此错误在我的计算机上消失了。
试试这个
string deviceFamilyVersion= AnalyticsInfo.VersionInfo.DeviceFamilyVersion;
ulong version = ulong.Parse(deviceFamilyVersion);
ulong major = (version & 0xFFFF000000000000L) >> 48;
ulong minor = (version & 0x0000FFFF00000000L) >> 32;
ulong build = (version & 0x00000000FFFF0000L) >> 16;
ulong revision = (version & 0x000000000000FFFFL);
var osVersion = $"{major}.{minor}.{build}.{revision}";
来源:
也许像这样的小帮手class?请注意,调用此方法的成本可能很高,因此建议执行一次并缓存数据。
(更新:如果你使用Windows组合API,你会发现AreEffectsFast
and AreEffectsSupported
很有帮助,因为您可以使用它们根据用户的设备和 OS 条件打开和关闭效果。我扩展了下面的 class 以将它们公开为两个新属性。)
public class BuildInfo
{
private static BuildInfo _buildInfo;
private BuildInfo()
{
if (ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 5))
{
Build = Build.FallCreators;
}
else if (ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 4))
{
Build = Build.Creators;
}
else if (ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 3))
{
Build = Build.Anniversary;
}
else if (ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 2))
{
Build = Build.Threshold2;
}
else if (ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 1))
{
Build = Build.Threshold1;
}
else
{
Build = Build.Unknown;
}
if (!BeforeCreatorsUpdate)
{
var capabilities = CompositionCapabilities.GetForCurrentView();
capabilities.Changed += (s, e) => UpdateCapabilities(capabilities);
UpdateCapabilities(capabilities);
}
void UpdateCapabilities(CompositionCapabilities capabilities)
{
AreEffectsSupported = capabilities.AreEffectsSupported();
AreEffectsFast = capabilities.AreEffectsFast();
}
}
public static Build Build { get; private set; }
public static bool AreEffectsFast { get; private set; }
public static bool AreEffectsSupported { get; private set; }
public static bool BeforeCreatorsUpdate => Build < Build.Creators;
public static BuildInfo RetrieveApiInfo() => _buildInfo ?? (_buildInfo = new BuildInfo());
}
public enum Build
{
Unknown = 0,
Threshold1 = 1507, // 10240
Threshold2 = 1511, // 10586
Anniversary = 1607, // 14393 Redstone 1
Creators = 1703, // 15063 Redstone 2
FallCreators = 1709 // 16299 Redstone 3
}
要初始化 class,请在 App.xaml.cs
中的 OnWindowCreated
之后立即调用它。
protected override void OnWindowCreated(WindowCreatedEventArgs args)
{
BuildInfo.RetrieveBuildInfo();
要使用它,只需调用
if (BuildInfo.Build == Build.Anniversary) { ... }
if (BuildInfo.BeforeCreatorsUpdate) { ... }
if (BuildInfo.AreEffectsFast) { ... }
使用前先使用SystemInformation Helper by UWPCommunityToolkit. Install Microsoft.Toolkit.Uwp Nuget包。
public OSVersion OperatingSystemVersion => SystemInformation.OperatingSystemVersion;
使用它您可以获得其他系统信息,例如 DeviceModel、DeviceManufacturer 等
更多信息:SystemInformation