MvvmCross.Core/Platform 5.7.0' 已使用 '.NETFramework,Version=v4.6.1' 而不是项目目标框架 '.NETStandard,Version=v2.0' 恢复

MvvmCross.Core/Platform 5.7.0' was restored using '.NETFramework,Version=v4.6.1' instead of the project target framework '.NETStandard,Version=v2.0'

我正在使用最新版本的 MvvmCross 创建 Android 和 iOS 应用程序。现在,由于便携式 class 库已弃用,我正在使用 .NET Standard 库 2.0 版。

我在 MvvmCross 的 NuGet 包中有这个警告.....虽然项目编译但我不确定我是否需要像最后一行所说的那样担心它

This package may not be fully compatible with your project.

下面是确切的警告

warning NU1701: Package 'MvvmCross.Core 5.7.0' was restored using '.NETFramework,Version=v4.6.1' instead of the project target framework '.NETStandard,Version=v2.0'. This package may not be fully compatible with your project.

MvvmCross.Platform 5.7.0

的类似警告

[

这个错误信息很简单,它意味着 MvvmCross 还没有更新到 net.standard。

在 Net.Standard 得到广泛采用之前,这将是掘金的常见错误。但是,在这种情况下有一个解决方案。

https://www.mvvmcross.com/documentation/getting-started/netstandard

When using .NET Standard 2 you do not need to specify a package target fallback. In .NET Standard 2 the PackageTargetFallback flag has been deprecated and instead defaults to net461 (.NET Framework 4.6.1) or higher. If however, this does not suit your use case you can override this behaviour with the AssetTargetFallback.

<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback>

正如 已经提到的,MvvmCross 版本 5.7.0 尚未更新为支持 .NET Standard。下一个主要版本 6.0.0 将添加对 .NET Standard 2.0 的支持。

但是可以在 .NET Standard class 库中使用 6.0.0 之前的 MvvmCross 版本。

为什么会出现警告?

您可以查看我对这个 问题给出的解释,了解为什么您会看到警告。摘录如下

With .NET Standard 2.0 and the updated tooling in .NET Core SDK 2+ the .NET team wanted to make it easier to update or make use of .NET Standard libraries. The issue is that not all NuGet packages have been updated to support a version of .NET Standard. So they introduced a fallback targeting .NET Framework 4.6.1 which is nearly 100% compliant with .NET Standard (There are some API that are in the .NET Standard 2.0 spec that are not in .NET Framework 4.6.1 but they can be brought in via NuGet packages if required). So the warning you see is to inform you that the packages do not conform to a .NET Standard version you are targeting and as such may contain API's that are not executable in your runtimes making use of your .NET Standard 2.0 library.

如何抑制警告

NuGet 提供了两个选项,每个包项目级别

每包

您可以编辑您的 csproj 并将 NoWarn="NU1701" 标记添加到包引用或 NuGet 包引用的 select 属性(解决方案资源管理器 > 依赖项 > NuGet > {包名称} 右键单击​​属性) 并将 NU1701 添加到 NoWarn 属性.

结果将类似于您的 csproj 中的以下内容

<ItemGroup>
  <PackageReference Include="MvvmCross" Version="5.7.0" NoWarn="NU1701" />
  <PackageReference Include="MvvmCross.Core" Version="5.7.0" NoWarn="NU1701" />
  <PackageReference Include="MvvmCross.Binding" Version="5.7.0" NoWarn="NU1701" />
  <PackageReference Include="MvvmCross.Platform" Version="5.7.0" NoWarn="NU1701" />
  <PackageReference Include="MvvmCross.CodeAnalysis" Version="5.7.0" NoWarn="NU1701" />
</ItemGroup> 

注意,使用每个包方法依赖包警告不会通过抑制父包来抑制。因此,您需要将包作为依赖项引入,以抑制警告。

项目级别

NuGet 还为您提供了在项目级别抑制所有 NU1701 警告的选项。您可以通过如下手动编辑 csproj 来完成此操作

<PropertyGroup>
  <NoWarn>NU1701</NoWarn>
</PropertyGroup>

或者通过 GUI,您可以修改 Suppress warnings 以包含 NU1701