如何在同一项目中定位netcoreapp2.0和net461 [英] How to target netcoreapp2.0 and net461 in the same project

查看:201
本文介绍了如何在同一项目中定位netcoreapp2.0和net461的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个要使用.net core 2.0的项目,我相信它是netcoreapp2.0.它还使用由.net 4.6.1创建的nuget程序包.我可以控制这个nuget包,并且可以根据需要更改.它确实具有作为nuget包导入的netstandards 2.0.

I've got a project that I want to use .net core 2.0, which I believe is netcoreapp2.0. It is also using a nuget package that is created with .net 4.6.1. I have control over this nuget package and can change something there if need be. It does have netstandards 2.0 imported as a nuget package.

如果我的cproj文件中包含:

If I include in my cproj file:

    <TargetFramework>netcoreapp2.0</TargetFramework>

我收到此警告:

使用'.NETFramework,Version = v4.6.1'而不是项目目标框架'.NETCoreApp,Version = v2.0'恢复了软件包'Terryberry.Roes.Common 2017.9.29-mongo'.该软件包可能与您的项目不完全兼容.

Package 'Terryberry.Roes.Common 2017.9.29-mongo' was restored using '.NETFramework,Version=v4.6.1' instead of the project target framework '.NETCoreApp,Version=v2.0'. This package may not be fully compatible with your project.

以及有关将system.net.sockets从4.3降级到4.1的错误. 4.6.1 nuget程序包具有System.Net.Sockets 4.3,所以我不确定为什么要降级.

along with errors about system.net.sockets being downgraded from 4.3 to 4.1. The 4.6.1 nuget package has System.Net.Sockets 4.3 so I'm not sure why it wants to downgrade.

确切的错误参考:

检测到的程序包降级:System.Net.Sockets从4.3.0降到4.1.0.直接从项目中引用该软件包以选择其他版本. MyNetCoreProject(> = 2017.2.0)-> Microsoft.VisualStudio.Web.BrowserLink(> = 1.1.2)-> Microsoft.Extensions.FileProviders.Physical(> = 1.1.1)-> NETStandard.Library(> = 1.6. 1)-> System.Net.Sockets(> = 4.3.0) MyNetCoreProject(> = 2017.2.0)-> Microsoft.VisualStudio.Web.BrowserLink(> = 1.1.2)-> System.Net.Sockets(> = 4.1.0)MyNetCoreProject

Detected package downgrade: System.Net.Sockets from 4.3.0 to 4.1.0. Reference the package directly from the project to select a different version. MyNetCoreProject (>= 2017.2.0) -> Microsoft.VisualStudio.Web.BrowserLink (>= 1.1.2) -> Microsoft.Extensions.FileProviders.Physical (>= 1.1.1) -> NETStandard.Library (>= 1.6.1) -> System.Net.Sockets (>= 4.3.0) MyNetCoreProject (>= 2017.2.0) -> Microsoft.VisualStudio.Web.BrowserLink (>= 1.1.2) -> System.Net.Sockets (>= 4.1.0) MyNetCoreProject

我尝试同时定位这两个目标

I tried targeting both:

    <TargetFrameworks>net461;netcoreapp2.0</TargetFrameworks>

这会给我类似警告:

使用'.NETFramework,Version = v4.6.1'而不是项目目标框架'.NETCoreApp,Version = v2.0'恢复了软件包'My461NugetPackage'.该软件包可能与您的项目不完全兼容.

Package 'My461NugetPackage' was restored using '.NETFramework,Version=v4.6.1' instead of the project target framework '.NETCoreApp,Version=v2.0'. This package may not be fully compatible with your project.

这也使我感到困惑,因为现在我添加了net461,它说它将使用.NetCoreApp来构建它.

This confuses me too because now I added net461 and it says its going to build it with .NetCoreApp

关于降级System.Net.Sockets仍然存在错误

There are still errors about downgrading System.Net.Sockets

然后我决定只愿意尝试net461.只是看它是否可以编译.可以,但是出现运行时错误.

I then decided I was willing to try just net461. Just to see if it would compile. It does, but I get a runtime error.

    <TargetFramework>net461</TargetFramework>

这给了我

未处理的异常:System.TypeLoadException:程序集"Microsoft.AspNetCore.Hosting"中的类型"Microsoft.AspNetCore.Hosting.WebHostBuilder"中的方法"ConfigureAppConfiguration",版本= 1.1.2.0,区域性=中性,PublicKeyToken = adb9793829ddae60'有一个实现.

Unhandled Exception: System.TypeLoadException: Method 'ConfigureAppConfiguration' in type 'Microsoft.AspNetCore.Hosting.WebHostBuilder' from assembly 'Microsoft.AspNetCore.Hosting, Version=1.1.2.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' does not have an implementation.

我尝试做一些研究,但是随着.net核心的不断发展,关于它的信息已经很多了/过时了.我还没弄清楚.任何指导将不胜感激.

I've tried doing some research, but there is a lot of old/obsolete information about there as .net core is evolving. I haven't been able to figure this out. Any guidance would be appreciated.

推荐答案

首先,您不能同时定位这两个目标.它们是互斥的.但是,这不是问题,因为您不需要这样做.

First off, you can't target both. They're mutually exclusive. However, that's not a problem, because you don't need to.

您收到的警告是设计使然.它不会阻止您的应用正常运行,也不会真正表明任何问题.就是这样:警告.让您知道您的.NET Core项目正在使用针对.NET Framework 4.6.1的库,当且仅当该库利用了刚发生的某些特定框架功能时,该问题可能会引起问题. .NET Standard 2.0不支持.在那里只是为了让您知道发生了什么,并且只要您所有应用程序的功能都能正常工作,就可以安全地将其忽略.如果警告本身困扰您,您可以简单地将其消除.

The warning you're getting is by design. It doesn't prevent your app from working or really indicate any problems at all. It's just that: a warning. It's letting you know that your .NET Core project is utilizing a library that targets .NET Framework 4.6.1, which could cause a problem if and only if that library utilizes some particular framework feature that just happens to not be supported by .NET Standard 2.0. It's there simply to make you aware of what's happening and can be safely ignored as long as all your application's functionality is working fine. If the warning itself bothers you, you can simply suppress it.

此警告不仅会在安装软件包时出现,还会在每次构建时出现.这样可以确保您不会意外忽略它.

This warning not only appears when installing the package, but every time you build. This ensures you don’t accidentally overlook it.

发出警告的原因是NuGet无法知道.NET Framework库是否将真正起作用.例如,它可能取决于Windows窗体.为了确保您不会浪费时间对无法解决的问题进行故障排除,NuGet会告诉您您可能会偏离正常轨道.当然,您必须忽略的警告很烦人.因此,我们建议您测试您的应用程序/库,如果发现一切正常,则可以消除该警告.

The reason for the warning is that NuGet has no way of knowing whether the .NET Framework library will actually work. For example, it might depend on Windows Forms. To make sure you don’t waste your time troubleshooting something that cannot work, NuGet lets you know that you’re potentially going off the rails. Of course, warnings you have to overlook are annoying. Thus, we recommend that you test your application/library and if you find everything is working as expected, you can suppress the warning.

来源: 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆