C# EF Core 3.1迁移工具因依赖于.NET Core 2.0而失败

C# EF Core 3.1迁移工具因依赖于.NET Core 2.0而失败,c#,entity-framework,.net-core,entity-framework-migrations,ef-core-3.1,C#,Entity Framework,.net Core,Entity Framework Migrations,Ef Core 3.1,我有一个使用EF Core 3.1的项目。启动项目是一个Azure函数,使用V3和framework 3.1运行。其余的项目是属于.NET标准2.0项目的类库 我正在尝试为EF Core 3.1生成迁移脚本,我从Azure DevOps收到以下错误 Starting: Run EF Core Migrations ============================================================================== Task

我有一个使用EF Core 3.1的项目。启动项目是一个Azure函数,使用V3和framework 3.1运行。其余的项目是属于.NET标准2.0项目的类库

我正在尝试为EF Core 3.1生成迁移脚本,我从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
当我查看执行dotnet.exe tool install dotnet ef-g时安装的工具的文件夹时,我可以看到有一个目录仍在引用framework 2.0,该目录存在于dotnet ef migrations脚本运行的命令中

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
我唯一能想到的是EF Core 3.1需要在构建服务器上安装.NET Core 2.0才能正常工作。然而,这感觉并不正确


有没有人经历过类似的事情?除了安装.NET Core 2.0之外,您是否找到了解决方案?

我想我找到了问题所在。我缺少--project参数。然而,一旦我把它放进去,我得到了以下错误:

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'

看起来EF Core迁移工具不像是Azure功能项目的启动项目。由于迁移项目是.NET标准的,所以我所做的是创建一个不做任何事情的控制台项目(只是一个带有console.Writelne(“”)的Program.CS,并使其引用包含迁移的项目,并将其用作我的启动项目。通过这样做,迁移工作正常。

此解决方案可能有助于尝试干净的构建。编译器无法识别库何时更改,因此中间对象文件使用的是Core2.0而不是Core3.1。生成由dotnet ef migrations脚本命令生成。你如何指导它进行干净的构建?