Efcore: Error creating DB migrations on 3.0.0

Created on 17 Oct 2019  路  23Comments  路  Source: dotnet/efcore

_From @deepak-khopade-isdr on Wednesday, October 16, 2019 8:56:59 PM_

Getting error creating DB migrations after upgrading to . NET Core 3.0.0

I recently updated .NET Core Framework on my linux docker containers from 1.1.0 to 3.0.0 and when trying to create migrations getting error for compatibility.

General

Running .NET Core 3.0.0 container with Ubuntu 18.04 (Linux).

Command: dotnet ef migrations add Initial

Output:

It was not possible to find any compatible framework version
The specified framework 'Microsoft.NETCore.App', version '2.0.7' was not found.
  - The following frameworks were found:
      3.0.0 at [/usr/share/dotnet/shared/Microsoft.NETCore.App]

You can resolve the problem by installing the specified framework and/or SDK.

The .NET Core frameworks can be found at:
  - https://aka.ms/dotnet-download

Platform info from 2 commands:

docker@03dda20017a9:/dotnet/app$ dotnet --version
3.0.100
docker@03dda20017a9:/dotnet/app$ dotnet --info
.NET Core SDK (reflecting any global.json):
 Version:   3.0.100
 Commit:    04339c3a26

Runtime Environment:
 OS Name:     ubuntu
 OS Version:  18.04
 OS Platform: Linux
 RID:         ubuntu.18.04-x64
 Base Path:   /usr/share/dotnet/sdk/3.0.100/

Host (useful for support):
  Version: 3.0.0
  Commit:  95a0a61858

.NET Core SDKs installed:
  3.0.100 [/usr/share/dotnet/sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.App 3.0.0 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 3.0.0 [/usr/share/dotnet/shared/Microsoft.NETCore.App]

To install additional .NET Core runtimes or SDKs:
  https://aka.ms/dotnet-download
docker@03dda20017a9:/dotnet/app$ 

Do I need to install SDK 2.0.7?

_Copied from original issue: dotnet/core#3646_

closed-external customer-reported

All 23 comments

@deepak-khopade-isdr Some things to check:

Yes @ajcvickers, and it says its already installed.

docker@03dda20017a9:/dotnet/app$ dotnet tool install --global dotnet-ef
Tool 'dotnet-ef' is already installed.
docker@03dda20017a9:/dotnet/app$ 

And I dont have global.json instead using .csproj to manage dependencies.

@ajcvickers : please find below the content of .csproj file:

<Project Sdk="Microsoft.NET.Sdk.Web">
  <PropertyGroup>
    <TargetFramework>netcoreapp3.0</TargetFramework>
    <AssemblyName>app</AssemblyName>
    <OutputType>Exe</OutputType>
  </PropertyGroup>
  <ItemGroup>
    <EmbeddedResource Remove="Resources\Startup.resx" />
  </ItemGroup>
  <ItemGroup>
    <ProjectReference Include="..\linqx\linqx.csproj" />
    <ProjectReference Include="..\xml\xml.csproj" />
    <ProjectReference Include="..\utilities\utilities.csproj" />
  </ItemGroup>
  <ItemGroup>
    <PackageReference Include="Elasticsearch.Net" Version="6.0.2" />
    <PackageReference Include="Gelf.Extensions.Logging" Version="1.1.0" />
    <PackageReference Include="Google.Apis.Auth" Version="1.32.0" />
    <PackageReference Include="Google.Apis.Storage.v1" Version="1.32.0.1076" />
    <PackageReference Include="htmldiff.net-core" Version="1.3.6" />
    <PackageReference Include="HtmlSanitizer" Version="3.4.156" />
    <PackageReference Include="Microsoft.AspNetCore.Diagnostics" Version="2.2.0" />
    <PackageReference Include="Microsoft.AspNetCore.JsonPatch" Version="3.0.0" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />
    <PackageReference Include="Microsoft.AspNetCore.Server.IISIntegration" Version="2.2.0" />
    <PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="2.2.0" />
    <PackageReference Include="Microsoft.AspNetCore.Session" Version="2.2.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.0.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.0.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.0.0" />
    <PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="3.0.0" />
    <PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="3.0.0" />
    <PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="3.0.0" />
    <PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="3.0.0" />
    <PackageReference Include="Microsoft.Extensions.Logging" Version="3.0.0" />
    <PackageReference Include="Microsoft.Extensions.Logging.Console" Version="3.0.0" />
    <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="3.0.0" />
    <PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="3.0.0" />
    <PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.2.0" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.0.0" />
    <PackageReference Include="Nest" Version="6.0.2" />
    <PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
    <PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="2.2.0" />
    <PackageReference Include="runtime.linux-x64.CoreCompat.System.Drawing" Version="1.0.0-*" />
    <PackageReference Include="Syslog.Framework.Logging" Version="1.0.0" />
    <PackageReference Include="HtmlAgilityPack.NetCore" Version="1.5.0.1" />
    <PackageReference Include="NEST.JsonNetSerializer" Version="6.0.2" />
    <PackageReference Include="NRules" Version="0.8.4" />
    <!--<PackageReference Include="DocumentFormat.OpenXml" Version="2.7.1" />-->
  </ItemGroup>
  <ItemGroup>
    <DotNetCliToolReference Include="Microsoft.DotNet.Watcher.Tools" Version="2.0.2" />
    <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.3" />
  </ItemGroup>
  <ItemGroup>
    <Folder Include="api\models\validation" />
    <Folder Include="Migrations" />
    <Folder Include="Resources\" />
    <Folder Include="static" />
  </ItemGroup>
  <PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
    <DefineConstants>$(DefineConstants);RELEASE</DefineConstants>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)' == 'Docker' ">
  </PropertyGroup>
</Project>

@deepak-khopade-isdr The project is pulling in a mixture of 2.2 and 3.0 EF packages. This generally doesn't work. For example, Pomelo.EntityFrameworkCore.MySql is based on EF Core 2.2. A 3.0 version is available in preview.

You should also check all your other 2.2 packages.

Thanks @ajcvickers. I will try and get back to you.

@ajcvickers, tried changing the Pomelo to its 3.0.0.preview, but no luck. Can you please review the .csproj one more time for any other library version I am misleading with?

@deepak-khopade-isdr What do you mean by, "no luck"?

I mean I changed the Pomelo.EntityFrameworkCore.MySql to 3.0.0-rc1.final, restored the project (dotnet restore) and then was running migrations command like below and getting the same error. When tried installing the dotnet-ef global tool, but it says its already installed. So not sure what's wrong. My project is building successfully so not sure what am I missing.

docker@03dda20017a9:/dotnet/app$ dotnet ef migrations add Initial
It was not possible to find any compatible framework version
The specified framework 'Microsoft.NETCore.App', version '2.0.7' was not found.
  - The following frameworks were found:
      3.0.0 at [/usr/share/dotnet/shared/Microsoft.NETCore.App]

You can resolve the problem by installing the specified framework and/or SDK.

The .NET Core frameworks can be found at:
  - https://aka.ms/dotnet-download
docker@03dda20017a9:/dotnet/app$ 

@deepak-khopade-isdr I see. Well all the ASP.NET Core packages are suspect, since they are all also 2.2. Other third-party packages may also have 2.2 dependencies.

May be this too

  <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.3" />

@smitpatel Good catch! That one for sure!

@ajcvickers , @smitpatel : I initially assumed all Microsoft.* packages to be 3.0.0 but then was getting errors as there are no packages available for most of my 2.x references here. E.g. refer this one: https://www.nuget.org/packages/Microsoft.EntityFrameworkCore.Tools.DotNet/

And hence I referred to the latest available from nuget.org for all those 2.x references you see.

Please let me know if I am missing something :thinking:

Per @smitpatel I changed the version to 3.0.0 but getting below error on dotnet restore:

error NU1102: Unable to find package Microsoft.EntityFrameworkCore.Tools.DotNet with version (>= 3.0.0)

dotnet-ef became part of SDK in 2.1 https://docs.microsoft.com/en-us/ef/core/what-is-new/ef-core-2.1#command-line-tool-dotnet-ef-included-in-net-core-sdk

And it became global tool in 3.0 https://docs.microsoft.com/en-us/ef/core/what-is-new/ef-core-3.0/breaking-changes#dotnet-ef

@deepak-khopade-isdr To be clear, I'm not suggesting that just speculatively updating package versions is the way to go. I'm suggesting that for each package you need to investigate and find out what the correct thing to do for .NET Core 3. In some cases this might be to remove the package completely.

ok @ajcvickers, will go package by package now. thanks.

@smitpatel : when I am trying to install EF Core 3.0.0 it says its already installed, so not sure if I have to install it again.

docker@03dda20017a9:/$ dotnet tool install --global dotnet-ef
Tool 'dotnet-ef' is already installed.
docker@03dda20017a9:/$ 

Thanks @ajcvickers & @smitpatel for all your inputs and directions. Finally got it right and needed to install .NET Core 2.1 alongside .NET Core 3.0 and finally getting somewhere. However, I had to use 2.0.0 version for Microsoft.DotNet.Watcher.Tools.

6 hours on this tonight, all my packages are up to date (as far as I know), dotnet outdated agrees. Large multi-project application with over 100 dependencies so impossible to audit them all. I installed .NET Core 2.1 which changed the error to

Could not load file or assembly 'netstandard, Version=2.1.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

EF Core 3.0 supports netstandard2.1 so you will need .NET Core 3.0 to run it.

@smitpatel I have .NET Core 3.0, my application targets netcoreapp3.0
I only installed 2.1 to get rid of the original error message 馃槙

Also, I know that

EF Core 3.0 supports netstandard2.1 so you will need .NET Core 3.0 to run it.

makes total sense to you guys on the team, but it's highly confusing to me.

@fergalmoran : my 2 cents on this; make sure you get .NET Core SDKs as both 2.1 and 3.0
installed alongside. And same for .NET Core runtime.

See my dotnet --info output.

.NET Core SDK (reflecting any global.json):
 Version:   3.0.100
 Commit:    04339c3a26

Runtime Environment:
 OS Name:     ubuntu
 OS Version:  18.04
 OS Platform: Linux
 RID:         ubuntu.18.04-x64
 Base Path:   /usr/share/dotnet/sdk/3.0.100/

Host (useful for support):
  Version: 3.0.0
  Commit:  95a0a61858

.NET Core SDKs installed:
  2.1.300 [/usr/share/dotnet/sdk]
  3.0.100 [/usr/share/dotnet/sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.1.13 [/usr/share/dotnet/shared/Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.13 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.0.0 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.1.13 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.0.0 [/usr/share/dotnet/shared/Microsoft.NETCore.App]

To install additional .NET Core runtimes or SDKs:
  https://aka.ms/dotnet-download

hi @deepak-khopade-isdr - 2 cents very much appreciated, thanks!

I do have 2.1 installed with 3.0 (but my 2.1 is 2.1.802)??

```dotnet --info
.NET Core SDK (reflecting any global.json):
Version: 3.0.100
Commit: 04339c3a26

Runtime Environment:
OS Name: ubuntu
OS Version: 19.04
OS Platform: Linux
RID: ubuntu.19.04-x64
Base Path: /usr/share/dotnet/sdk/3.0.100/

Host (useful for support):
Version: 3.0.0
Commit: 95a0a61858

.NET Core SDKs installed:
2.1.802 [/usr/share/dotnet/sdk]
3.0.100 [/usr/share/dotnet/sdk]

.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.1.13 [/usr/share/dotnet/shared/Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.13 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.0.0 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.1.13 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 3.0.0 [/usr/share/dotnet/shared/Microsoft.NETCore.App]

To install additional .NET Core runtimes or SDKs:
https://aka.ms/dotnet-download
```

Was this page helpful?
0 / 5 - 0 ratings