Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
395 views
in Technique[技术] by (71.8m points)

c# - dotnet restore warning NU1701

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

PS C:workspaceArbitrator> dotnet restore

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.

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You don't necessarily have to wait until PusherClient is upgraded for .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. You can just suppress this warning

    • for a specific package
     <PackageReference Include="Contoso.Base.API" Version="1.0.3">
         <NoWarn>NU1701</NoWarn>
     </PackageReference>
    
    • for all packages
     <NoWarn>NU1701</NoWarn>
    

    See scenarios 2 and 3 in NuGet wiki for ways to do it from GUI.

    It is possible, though, that your application may fail in run-time when you call an API (like something from WPF) that is not supported by .NET Core. Another reason of a failure could be native APIs possibly used by PusherClient. So you should test it extensively. But in most cases, it will just work on all platforms where .NET Core is 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).

  2. 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>
    

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...