由于对 .NET Core 2.0 的依赖,EF Core 3.1 迁移工具失败
EF Core 3.1 Migration Tool is failing because of a dependency on .NET Core 2.0
我有一个使用 EF Core 3.1 的项目。启动项目是 运行ning 使用 V3 和框架 3.1 的 Azure 函数。其余项目是 class 个属于 .NET Standard 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\s/MyProject/MyProject.Function.WebApi/MyProject.Function.WebApi.csproj --output C:\vstsagent\A6\_work\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\_temp30c14d-f779-4939-9748-dd2ab8c6baa0.cmd""
Using project 'C:\vstsagent\A6\_work\s/MyProject/MyProject.Function.WebApi/MyProject.Function.WebApi.csproj'.
Using startup project 'C:\vstsagent\A6\_work\s/MyProject/MyProject.Function.WebApi/MyProject.Function.WebApi.csproj'.
Writing 'C:\vstsagent\A6\_work\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\s/MyProject/MyProject.Function.WebApi/MyProject.Function.WebApi.csproj
Writing 'C:\vstsagent\A6\_work\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\s/MyProject/MyProject.Function.WebApi/MyProject.Function.WebApi.csproj
Build started...
Build succeeded.
dotnet exec --depsfile C:\vstsagent\A6\_work\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.1.1\dotnet-ef.1.1\tools\netcoreapp3.1\any\tools\netcoreapp2.0\any\ef.dll migrations script --output C:\vstsagent\A6\_work\a/16138/Migrations/covImsSqlScript.sql --context $dbContext --idempotent --assembly C:\vstsagent\A6\_work\s\MyProject\MyProject.Function.WebApi\bin\Debug\netcoreapp3.1\MyProject.Function.WebApi.dll --startup-assembly C:\vstsagent\A6\_work\s\MyProject\MyProject.Function.WebApi\bin\Debug\netcoreapp3.1\MyProject.Function.WebApi.dll --project-dir C:\vstsagent\A6\_work\s\MyProject\MyProject.Function.WebApi\ --language C# --working-dir C:\vstsagent\A6\_work\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 时安装的工具的文件夹时,我可以看到有一个目录那仍然引用框架 2.0,它存在于 dotnet ef 迁移脚本 运行 的命令中。
C:\Windows\ServiceProfiles\NetworkService\.dotnet\tools\.store\dotnet-ef.1.1\dotnet-ef.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 Function Project 的启动项目。由于迁移项目是 .NET Standard,我所做的是创建一个什么也不做的控制台项目(只是 Program.CS 和 Console.Writelne(""))并使其引用包含迁移的项目并将其用作我的启动项目。通过这样做,迁移工作正常。
我有一个使用 EF Core 3.1 的项目。启动项目是 运行ning 使用 V3 和框架 3.1 的 Azure 函数。其余项目是 class 个属于 .NET Standard 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\s/MyProject/MyProject.Function.WebApi/MyProject.Function.WebApi.csproj --output C:\vstsagent\A6\_work\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\_temp30c14d-f779-4939-9748-dd2ab8c6baa0.cmd""
Using project 'C:\vstsagent\A6\_work\s/MyProject/MyProject.Function.WebApi/MyProject.Function.WebApi.csproj'.
Using startup project 'C:\vstsagent\A6\_work\s/MyProject/MyProject.Function.WebApi/MyProject.Function.WebApi.csproj'.
Writing 'C:\vstsagent\A6\_work\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\s/MyProject/MyProject.Function.WebApi/MyProject.Function.WebApi.csproj
Writing 'C:\vstsagent\A6\_work\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\s/MyProject/MyProject.Function.WebApi/MyProject.Function.WebApi.csproj
Build started...
Build succeeded.
dotnet exec --depsfile C:\vstsagent\A6\_work\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.1.1\dotnet-ef.1.1\tools\netcoreapp3.1\any\tools\netcoreapp2.0\any\ef.dll migrations script --output C:\vstsagent\A6\_work\a/16138/Migrations/covImsSqlScript.sql --context $dbContext --idempotent --assembly C:\vstsagent\A6\_work\s\MyProject\MyProject.Function.WebApi\bin\Debug\netcoreapp3.1\MyProject.Function.WebApi.dll --startup-assembly C:\vstsagent\A6\_work\s\MyProject\MyProject.Function.WebApi\bin\Debug\netcoreapp3.1\MyProject.Function.WebApi.dll --project-dir C:\vstsagent\A6\_work\s\MyProject\MyProject.Function.WebApi\ --language C# --working-dir C:\vstsagent\A6\_work\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 时安装的工具的文件夹时,我可以看到有一个目录那仍然引用框架 2.0,它存在于 dotnet ef 迁移脚本 运行 的命令中。
C:\Windows\ServiceProfiles\NetworkService\.dotnet\tools\.store\dotnet-ef.1.1\dotnet-ef.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 Function Project 的启动项目。由于迁移项目是 .NET Standard,我所做的是创建一个什么也不做的控制台项目(只是 Program.CS 和 Console.Writelne(""))并使其引用包含迁移的项目并将其用作我的启动项目。通过这样做,迁移工作正常。