问题描述
我正在将C#与.NETCore一起使用,当我执行 dotnet恢复
时,出现以下错误:
I am using .NETCore with C# and when I did dotnet restore
it gave the following error:
C:\workspace\Arbitrator\Arbitrator.csproj:警告NU1701 :使用 .NETFramework,Version = v4.6.1而不是项目目标框架 .NETCoreApp,Version = v2.0恢复了软件包 PusherClient 0.5.0。这可能会导致兼容性问题。
C:\workspace\Arbitrator\Arbitrator.csproj:警告NU1701:使用'.NETFramework,Version = v4.6.1'代替了项目目标框架'.NETCoreApp,恢复了'WebSocket4Net 0.14.1'软件包,版本= v2.0。这可能会导致兼容性问题。
C:\workspace\Arbitrator\Arbitrator.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:\workspace\Arbitrator\Arbitrator.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.
有问题的软件包为,我只是按照掘金文件将其导入,如何解决此警告?
This package in problem is PusherClient, I just followed the nugget 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 .NET Core的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.
-
您可以禁止显示该警告
You can just suppress this warning
- fo ra特定软件包
<PackageReference Include="Contoso.Base.API" Version="1.0.3">
<NoWarn>NU1701</NoWarn>
</PackageReference>
- 所有套餐
<NoWarn>NU1701</NoWarn>
。
但是,当您调用.NET Core不支持的
的API(例如WPF中的某些功能)时,应用程序可能会在运行时
中失败。失败的另一个原因可能是 PusherClient 可能使用的本机API
。因此,您应该对其进行广泛的测试。
但在大多数情况下,它将仅在支持.NET Core
的所有平台上运行(例如,我已经测试了具有
MathNet.Numerics 依赖项的应用程序即使
MathNet.Numerics 也是.NET Framework 4.6.1),它也可以在Linux上运行。
It is possible, though, that you 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 with MathNet.Numerics dependency and it worked on Linux even though MathNet.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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!