I am in the process of upgrading .NET Core to 2.1 in my app. With the latest SDK (2.1.300), .NET Standard has two versions of Entity Framework Core. So, when I right click the line below and click "Go To Definition" I get the options in the below screenshot.
using Microsoft.EntityFrameworkCore;
Notice both 2.1.0.0 and 2.0.3.0 of Entity Framework Core. I am assuming that, by default, I am targeting the highest version available (2.1.0.0). I would like to specifically target 2.0.3.0 since I believe my class library's EF data provider currently has an incompatibility with 2.1.0.0. But, I would like to continue using the latest version of the SDK. Is there a way to achieve this by somehow specifying the version number of Microsoft.EntityFrameworkCore
to use?
I have already worked through the 2.x to 2.1 migration guide if that matters. Here are the relevant parts of my class library's .csproj for reference:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.0.3" />
</ItemGroup>
</Project>
You seem to be mixing up some things there:
2.1.300
of the SDK. The SDK version has no direct impact on what runtime you will be using.netcoreapp2.1
target framework.Microsoft.AspNetCore.*
packages with version 2.1.Microsoft.AspNetCore.App
in that case.So a project that uses ASP.NET Core 2.1 on .NET Core 2.1, using Entity Framework 2.0 with the Pomelo MySQL provider could look like this:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore" Version="2.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.0.3" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="2.0.1" />
</ItemGroup>
</Project>
If you are not trying to do this within an ASP.NET Core web project but in a library project instead, then you are targetting netstandard2.0
. In that case, you just need to import the proper packages directly:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.0.3" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="2.0.1" />
</ItemGroup>
</Project>
Note that Entity Framework Core is not included in the .NET Standard, it is merely targetting it which means that it builds on top of the standard; just like your library project.
If you want to consume your library project from within an ASP.NET Core 2.1 application, then the restriction mentioned above will still apply: You cannot use the Microsoft.AspNetCore.App
shared framework reference, since that will cause version conflicts.