Azure Pipeline中安装EF Core及执行迁移报错求助
.NET 6 Azure流水线添加EF Core迁移步骤的问题排查
现有一条用于将.NET 6项目构建并部署到Azure Web App(搭配Azure SQL)的流水线,尝试添加Entity Framework Core迁移步骤时遇到一系列问题,具体尝试过程及错误如下:
尝试1:使用DotNetCoreCLI全局安装EF工具
使用以下YAML步骤安装dotnet-ef工具:
- task: DotNetCoreCLI@2 displayName: 'Install EF tool' inputs: command: 'custom' custom: 'tool' arguments: 'install dotnet-ef --global --version 7.0.5'
执行失败,报401未授权错误,无法访问Azure Artifacts源:
Unhandled exception: NuGet.Protocol.Core.Types.FatalProtocolException: Unable to load the service index for source https://pkgs.dev.azure.com/OneHRADO/<removed the guid here>/_packaging/OneHRADO_PublicPackages/nuget/v3/index.json. ---> System.Net.Http.HttpRequestException: Response status code does not indicate success: 401 (Unauthorized).
该URL与Visual Studio中“连接到源”的设置一致,但修改nuget.config后访问地址未发生变化。
尝试2:指定Feed ID的DotNetCoreCLI命令
使用与NuGet还原步骤相同的Feed ID,调整YAML:
- task: DotNetCoreCLI@2 displayName: 'Install EF tool' inputs: command: 'custom' custom: 'tool' arguments: 'install dotnet-ef -g --version 7.0.5' feedsToUse: 'select' vstsFeed: '<FeedId>' #actual Id removed
仍报相同的401未授权错误。
尝试3:使用NuGetCommand安装
改用NuGetCommand任务尝试:
- task: NuGetCommand@2 displayName: 'Install EF tool' inputs: command: 'custom' arguments: 'install dotnet-ef -Version 7.0.5' feedsToUse: 'select' vstsFeed: '<FeedId>' #actual Id removed
此次成功找到源并开始安装,但最终报错NU5000并回滚:
Error NU5000: Package 'dotnet-ef 7.0.5' has a package type 'DotnetTool' that is not supported by project 'D:\a\1\s'
更新尝试:直接运行迁移脚本生成命令
发现Artifact源中已存在dotnet-ef包且已执行NuGet Restore,尝试直接运行生成迁移脚本的命令:
- task: DotNetCoreCLI@2 displayName: 'Generate SQL Script' inputs: command: 'custom' custom: 'ef' arguments: 'migrations script --idempotent --project "$(Build.SourcesDirectory)\HR Taxonomy Change Management"\*.csproj --output $(System.ArtifactsDirectory)\script.sql'
执行失败,提示:
Could not execute because the specified command or file was not found.
内容的提问来源于stack exchange,提问作者USMC6072
相关产品推荐
相关产品推荐

