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
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 <TargetFramework>
in the csproj. It is this <TargetFramework>
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:
<TargetFramework>
is "net461" or similarEdit: 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 <PackageReference ... />
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.
Related answer: https://stackoverflow.com/a/54116368/10891544
To target multiple frameworks from a .net core project, open up your .csproj file and replace the TargetFramework tag with a new TargetFrameworks tag:
<TargetFrameworks>net461;netcoreapp2.0</TargetFrameworks>
This should allow you to use .NET Framework packages from a .NET Core project. However, you will lose the ability to run your code cross-platform.