Azure 2019 CI本地代理运行dotnet format校验报运行时错误如何解决
运行时不匹配问题解决方法
你遇到的报错根本原因是:下载的dotnet-format v5.1.225507版本默认依赖.NET 6运行时,而代理环境仅安装了.NET 5.0.201 SDK,二者版本不兼容。你可以选择以下任意一种方案解决:
方案1:添加运行时回滚参数,强制使用现有.NET 5 SDK运行
不需要更换dotnet-format版本,只需修改校验步骤的运行参数,添加--roll-forward LatestMajor参数即可,修改后的YAML配置如下:
# working build and test here... - task: DotNetCoreCLI@2 displayName: 'dotnet install dotnet-format' inputs: command: custom custom: tool arguments: 'update -g dotnet-format --configfile ./.nuget/NuGetBuildServer.Config' - task: DotNetCoreCLI@2 displayName: 'Validiere Codestil' inputs: command: custom custom: format arguments: '-v diag --configfile ./.nuget/NuGetBuildServer.Config --check --verbosity diagnostic --no-restore --verify-no-changes --severity info --roll-forward LatestMajor' # working publishing here...
该参数会让dotnet工具自动兼容使用已安装的最高版本主运行时。
方案2:安装适配.NET 5 SDK的dotnet-format版本
dotnet-format v5.0.211103及更早的5.0.x分支版本原生适配.NET 5 SDK,你可以将本地源中的dotnet-format替换为该版本,安装时明确指定版本号即可:
arguments: 'update -g dotnet-format --version 5.0.211103 --configfile ./.nuget/NuGetBuildServer.Config'
后续运行校验步骤不需要额外加参数即可正常运行。
方案3:添加global.json文件锁定SDK版本
在代码仓库根目录新增global.json文件,内容如下:
{ "sdk": { "version": "5.0.201", "rollForward": "latestMinor" } }
所有dotnet命令执行时会优先读取该配置,锁定使用你指定的5.0.201版本SDK,从根源上避免运行时版本选择错误。
内容的提问来源于stack exchange,提问作者finder2
相关产品推荐
相关产品推荐

