使用Azure经典编辑器构建管道遇.NET 5与低版本Nuget兼容问题求助
解决Azure Pipeline中.NET 5与旧版NuGet兼容性问题的具体步骤
先明确错误原因:
.NET 5 has some compatibility issues with older Nuget versions(<=5.7), so if you are using an older Nuget version(and not dotnet cli) to restore, then the dotnet cli commands (e.g. dotnet build) which rely on such restored packages might fail. To mitigate such error, you can either: (1) - Use dotnet cli to restore, (2) - Use Nuget version 5.8 to restore, (3) - Use global.json using an older sdk version(<=3) to build
以下是三个方案的具体操作步骤,针对Azure经典编辑器:
方案1:改用dotnet CLI做包还原
- 打开Azure经典编辑器,找到Pipeline里的NuGet Restore任务,直接删除
- 添加Dotnet Core任务:点击任务列表上方的「添加任务」,搜索并选择Dotnet Core
- 配置任务参数:
- 命令下拉选择
restore - 项目/解决方案路径填写你的项目路径,比如
**/*.sln - 其他参数保持默认即可
- 命令下拉选择
- 后续的
dotnet build任务记得指定SDK版本为5.x(在Dotnet Core任务的「SDK版本」选项里选5.x)
方案2:升级NuGet版本到5.8及以上
- 在Pipeline里找到现有的NuGet Restore任务
- 点开任务设置,找到「NuGet版本」选项
- 选择「指定版本」,输入
5.8.0或者更高的稳定版本(比如6.4.0) - 保存配置后重新运行Pipeline
方案3:用global.json指定旧版SDK(<=3.x)构建
- 在你的项目根目录新建
global.json文件,内容如下:{ "sdk": { "version": "3.1.426" // 换成任意3.x系列的稳定版都可以 } } - 把这个文件提交到代码仓库
- 回到Azure经典编辑器,找到Pipeline里的Dotnet Core任务,把「SDK版本」设为「Use global.json」,或者直接指定对应的3.x版本
- 重新运行构建任务
内容的提问来源于stack exchange,提问作者divya bommerla
相关产品推荐
相关产品推荐

