Efcore: EF Core 3.1 Migration Tool is failing because of a dependency on .NET Core 2.0

Created on 14 Feb 2020  路  11Comments  路  Source: dotnet/efcore

Hello

I have a project that uses EF Core 3.1. The startup project is an Azure Function that is running using V3 and framework 3.1. The rest of the projects are class libraries that are .NET Standard 2.0 projects.

I am trying to generate a migration script for EF Core 3.1 and I am getting the following error from Azure DevOps

Starting: Run EF Core Migrations
==============================================================================
Task         : Command line
Description  : Run a command line script using Bash on Linux and macOS and cmd.exe on Windows
Version      : 2.163.0
Author       : Microsoft Corporation
Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/utility/command-line
==============================================================================
Generating script.
Script contents:
dotnet ef migrations script --startup-project C:\vstsagent\A6\_work\2\s/MyProject/MyProject.Function.WebApi/MyProject.Function.WebApi.csproj --output C:\vstsagent\A6\_work\2\a/16138/Migrations/SqlScript.sql --context $dbContext --idempotent --verbose --framework netcoreapp3.1
========================== Starting Command Output ===========================
"C:\Windows\system32\cmd.exe" /D /E:ON /V:OFF /S /C "CALL "C:\vstsagent\A6\_work\_temp\3930c14d-f779-4939-9748-dd2ab8c6baa0.cmd""
Using project 'C:\vstsagent\A6\_work\2\s/MyProject/MyProject.Function.WebApi/MyProject.Function.WebApi.csproj'.
Using startup project 'C:\vstsagent\A6\_work\2\s/MyProject/MyProject.Function.WebApi/MyProject.Function.WebApi.csproj'.
Writing 'C:\vstsagent\A6\_work\2\s\MyProject\MyProject.Function.WebApi\obj\MyProject.Function.WebApi.csproj.EntityFrameworkCore.targets'...
dotnet msbuild /target:GetEFProjectMetadata /property:EFProjectMetadataFile=C:\Windows\ServiceProfiles\NetworkService\AppData\Local\Temp\tmp74C6.tmp /verbosity:quiet /nologo C:\vstsagent\A6\_work\2\s/MyProject/MyProject.Function.WebApi/MyProject.Function.WebApi.csproj
Writing 'C:\vstsagent\A6\_work\2\s\MyProject\MyProject.Function.WebApi\obj\MyProject.Function.WebApi.csproj.EntityFrameworkCore.targets'...
dotnet msbuild /target:GetEFProjectMetadata /property:EFProjectMetadataFile=C:\Windows\ServiceProfiles\NetworkService\AppData\Local\Temp\tmp77C5.tmp;TargetFramework=netcoreapp3.1 /verbosity:quiet /nologo C:\vstsagent\A6\_work\2\s/MyProject/MyProject.Function.WebApi/MyProject.Function.WebApi.csproj
Build started...

Build succeeded.
dotnet exec --depsfile C:\vstsagent\A6\_work\2\s\MyProject\MyProject.Function.WebApi\bin\Debug\netcoreapp3.1\MyProject.Function.WebApi.deps.json --additionalprobingpath C:\Windows\ServiceProfiles\NetworkService\.nuget\packages C:\Windows\ServiceProfiles\NetworkService\.dotnet\tools\.store\dotnet-ef\3.1.1\dotnet-ef\3.1.1\tools\netcoreapp3.1\any\tools\netcoreapp2.0\any\ef.dll migrations script --output C:\vstsagent\A6\_work\2\a/16138/Migrations/covImsSqlScript.sql --context $dbContext --idempotent --assembly C:\vstsagent\A6\_work\2\s\MyProject\MyProject.Function.WebApi\bin\Debug\netcoreapp3.1\MyProject.Function.WebApi.dll --startup-assembly C:\vstsagent\A6\_work\2\s\MyProject\MyProject.Function.WebApi\bin\Debug\netcoreapp3.1\MyProject.Function.WebApi.dll --project-dir C:\vstsagent\A6\_work\2\s\MyProject\MyProject.Function.WebApi\ --language C# --working-dir C:\vstsagent\A6\_work\2\s --verbose --root-namespace MyProject.Function.WebApi
It was not possible to find any compatible framework version
The framework 'Microsoft.NETCore.App', version '2.0.0' was not found.
  - The following frameworks were found:
      3.1.0 at [C:\vstsagent\A6\_work\_tool\dotnet\shared\Microsoft.NETCore.App]
      3.1.1 at [C:\vstsagent\A6\_work\_tool\dotnet\shared\Microsoft.NETCore.App]

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

The specified framework can be found at:
  - https://aka.ms/dotnet-core-applaunch?framework=Microsoft.NETCore.App&framework_version=2.0.0&arch=x64&rid=win81-x64
##[error]Cmd.exe exited with code '-2147450730'.
Finishing: Run EF Core Migrations

When I look into the folder of the tool that gets installed when you execute dotnet.exe tool install dotnet-ef -g I can see that there is a directory that is still referencing the framework 2.0, which is present on the command that dotnet ef migrations script run.

C:\Windows\ServiceProfiles\NetworkService\.dotnet\tools\.store\dotnet-ef\3.1.1\dotnet-ef\3.1.1\tools\netcoreapp3.1\any\tools\netcoreapp2.0\any\ef.dll

The only thing I can think of is that EF Core 3.1 needs .NET Core 2.0 to also be installed on the build server for it to work. However, that does not feel right.

Has anyone experienced something similar and did you manage to find a solution other than installing .NET Core 2.0?

Further technical details

EF Core version: 3.1
Database provider: Microsoft Azure SQL
Target framework: 3.1
Operating system: Windows Server 2012 R2
IDE: N/A

closed-question customer-reported

Most helpful comment

i have same issue for migration

All 11 comments

@magoicochea I'm not sure what is going on here. EF Core 3.x certainly doesn't depend on anything 2.0. However, Azure Functions has historically had its own dependencies that can interfere with what the app is using--have you followed up with that team?

It could also be that some project reference is transitively bringing in 2.0. Can you post your csproj files so we can look at the dependencies?

Hello

I think I found what was the issue. I was missing the --project parameter. However, once I put it I was getting the following error:

Error:
  An assembly specified in the application dependencies manifest (MyProject.Function.WebApi.deps.json) was not found:
    package: 'MyProject.Common', version: '1.0.0'
    path: 'MyProject.Common.dll'

It looks like the EF Core Migration Tool does not like a startup project that is an Azure Function Project. Since the migration project is .NET Standard what I did was to create a console project that does nothing (just a Program.CS with a Console.Writelne("")) and make it reference the project that contained the migrations and use it as my Startup Project. By doing that migrations are working fine.

Nevertheless, I am not very happy with the workaround. I am not sure if there is a better way and the error messages thrown by the EF Core Tool were very confusing and leading me into the wrong direction.

@magoicochea

error messages thrown by the EF Core Tool were very confusing and leading me into the wrong direction

Can you elaborate on what these messages were?

Sure, they are included on my previous messages, but they were the following. When I was using the "--startup-project" instead of the "--project" flag I was getting this error

dotnet exec --depsfile C:\vstsagent\A6\_work\2\s\MyProject\MyProject.Function.WebApi\bin\Debug\netcoreapp3.1\MyProject.Function.WebApi.deps.json --additionalprobingpath C:\Windows\ServiceProfiles\NetworkService\.nuget\packages C:\Windows\ServiceProfiles\NetworkService\.dotnet\tools\.store\dotnet-ef\3.1.1\dotnet-ef\3.1.1\tools\netcoreapp3.1\any\tools\netcoreapp2.0\any\ef.dll migrations script --output C:\vstsagent\A6\_work\2\a/16138/Migrations/covImsSqlScript.sql --context $dbContext --idempotent --assembly C:\vstsagent\A6\_work\2\s\MyProject\MyProject.Function.WebApi\bin\Debug\netcoreapp3.1\MyProject.Function.WebApi.dll --startup-assembly C:\vstsagent\A6\_work\2\s\MyProject\MyProject.Function.WebApi\bin\Debug\netcoreapp3.1\MyProject.Function.WebApi.dll --project-dir C:\vstsagent\A6\_work\2\s\MyProject\MyProject.Function.WebApi\ --language C# --working-dir C:\vstsagent\A6\_work\2\s --verbose --root-namespace MyProject.Function.WebApi
It was not possible to find any compatible framework version
The framework 'Microsoft.NETCore.App', version '2.0.0' was not found.
  - The following frameworks were found:
      3.1.0 at [C:\vstsagent\A6\_work\_tool\dotnet\shared\Microsoft.NETCore.App]
      3.1.1 at [C:\vstsagent\A6\_work\_tool\dotnet\shared\Microsoft.NETCore.App]

When I made my EF Core project on the --project flag and added the azure function as the startup project I got the following error:

Error:
  An assembly specified in the application dependencies manifest (MyProject.Function.WebApi.deps.json) was not found:
    package: 'MyProject.Common', version: '1.0.0'
    path: 'MyProject.Common.dll'

@magoicochea Can you attach a project that generates the errors? They are coming from the .NET SDK rather than from EF, but we would like to understand the root cause and potentially use that information to make the SDK experience better.

EF Team Triage: Closing this issue as the requested additional details have not been provided and we have been unable to reproduce it.

BTW this is a canned response and may have info or details that do not directly apply to this particular issue. While we'd like to spend the time to uniquely address every incoming issue, we get a lot traffic on the EF projects and that is not practical. To ensure we maximize the time we have to work on fixing bugs, implementing new features, etc. we use canned responses for common triage decisions.

i have same issue for migration

Having the same issue with migrations.

Same here! :)

Hint: Ensure that the Microsoft.EntityFrameworkCore.Design NuGet package is installed for the project. I got the error in question for a project where it was missing. The issue had nothing to do with Azure in my case.

I still had this issue in 3.1 (both VS2019 and 2019 preview), the only way I could resolve it was with post build events to copy artifacts.
https://github.com/dotnet/efcore/issues/14679#issuecomment-550245010

Was this page helpful?
0 / 5 - 0 ratings