本文介绍了dotnet 恢复警告 NU1701的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 C# 中使用 .NET Core,当我执行 dotnet restore 时,出现以下错误:

I am using .NET Core with C#, and when I did dotnet restore, it gave the following error:

PS C:workspaceArbitrator>dotnet 还原

C:workspaceArbitratorArbitrator.csproj:警告 NU1701:使用.NETFramework,Version=v4.6.1"而不是项目目标框架.NETCoreApp,Version=v2"还原包PusherClient 0.5.0".0'.这可能会导致兼容性问题.C:workspaceArbitratorArbitrator.csproj:警告 NU1701:使用.NETFramework,Version=v4.6.1"而不是项目目标框架.NETCoreApp,Version=v2.0"还原包WebSocket4Net 0.14.1".这可能会导致兼容性问题.

C:workspaceArbitratorArbitrator.csproj : warning NU1701: Package 'PusherClient 0.5.0' was restored using '.NETFramework,Version=v4.6.1' instead the project target framework '.NETCoreApp,Version=v2.0'. This may cause compatibility problems.C:workspaceArbitratorArbitrator.csproj : warning NU1701: Package 'WebSocket4Net 0.14.1' was restored using '.NETFramework,Version=v4.6.1' instead the project target framework '.NETCoreApp,Version=v2.0'. This may cause compatibility problems.

这个有问题的包是PusherClient.我只是按照 NuGet 文档来导入它.我该如何解决这个警告?

This package in problem is PusherClient. I just followed the NuGet documents to import it. How can I fix this warning?

推荐答案

您不必等到 PusherClient 针对 .NET Core 升级.

You don't necessarily have to wait until PusherClient is upgraded for .NET Core.

从 .NET Core 引用 .NET Framework 4.6.1(及以下)是一个 新功能 自 .NET Core/Standard 2.0 预览版 2 起可用/VS 2017 预览版 15.3,根据 MS 的说法,可以将其视为一种功能,可帮助您随着时间的推移将 .NET Framework 代码迁移到 .NET Standard 或 .NET Core.

Referencing .NET Framework 4.6.1 (and below) from .NET Core is a new feature available since .NET Core/Standard 2.0 preview 2 / VS 2017 preview 15.3, and according to MS, it can be thought of as a feature that helps you migrate .NET Framework code to .NET Standard or .NET Core over time.

  1. 您可以取消此警告

  1. You can just suppress this warning

  • 对于特定的包
 <PackageReference Include="Contoso.Base.API" Version="1.0.3">
     <NoWarn>NU1701</NoWarn>
 </PackageReference>

  • 对于所有包
  •  <NoWarn>NU1701</NoWarn>
    

    参见 NuGet wiki 中的场景 2 和 3 以了解方法从 GUI 中完成.

    不过,您的应用程序可能会在运行时失败当您调用不受支持的 API(如 WPF 中的某些内容)时通过 .NET Core.失败的另一个原因可能是本机 API可能被 PusherClient 使用.所以你应该广泛地测试它.但在大多数情况下,它只适用于 .NET Core 的所有平台支持(例如,我测试了一个应用程序MathNet.Numerics 依赖项,即使在 Linux 上也能运行MathNet.Numerics 也是 .NET Framework 4.6.1).

    It is possible, though, that your application may fail in run-timewhen you call an API (like something from WPF) that is not supportedby .NET Core. Another reason of a failure could be native APIspossibly used by PusherClient. So you should test it extensively.But in most cases, it will just work on all platforms where .NET Coreis supported (for example, I have tested an application withMathNet.Numerics dependency and it worked on Linux even thoughMathNet.Numerics is also .NET Framework 4.6.1).

    如果您的应用不需要跨平台,只需将以下内容添加到您的 csproj 文件中,将其目标框架更改为 .NET 4.6.1:

    If you don't need your app to be cross-platform, just change its target framework to .NET 4.6.1 by adding the following to your csproj file:

     <TargetFramework>net461</TargetFramework>
    

    这篇关于dotnet 恢复警告 NU1701的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 23:06