reference .Net framework 4.5.2 from .Net Core 2.0 project

后端 未结 2 1111
栀梦
栀梦 2021-01-19 23:27

I have spent a few hours trying to figure out why .Net Core 2.0 wouldn\'t load .Net framework 4.5.2 nuget packages.

Now I think it\'s time to ask...

What hap

2条回答
  •  不知归路
    2021-01-20 00:01

    asp.net core can target multiple frameworks; a 2.0 web app will typically run on either "netcoreapp2.0" (a .NET Core application) or "net461" (a .NET application), for example - as specified by the in the csproj. It is this that determines how all the downstream package resolution will work. If it is "net461", it may be happy to take a "net452" library. However, "netcoreapp2.0" will not want "net452" - instead preferring "netstandard2.0" or "netstandard1.6", etc. Targeting .NET Standard will mean that all downstream packages also need to target .NET Standard, which is not always possible.

    So:

    • if possible, make your dependencies target some version of .NET Standard
    • if that isn't possible, ensure that the is "net461" or similar

    Edit: it looks like the default projects also change between Microsoft.AspNetCore (when targeting .NET) and Microsoft.AspNetCore.All (when targeting .NET Core) - so you may also need to change that entry in the csproj. If you are using any of the extra packages in Microsoft.AspNetCore.All that aren't in Microsoft.AspNetCore - you may need to add the ones that you need manually.

提交回复
热议问题