如何使用DotNetCoreCLI@2避免还原Git子模块
解决DotNetCoreCLI@2 Restore命令自动检出子模块的问题
核心问题原因
DotNetCoreCLI的restore命令默认会尝试处理项目中的Git子模块依赖,这会和你已通过PowerShell完成的子模块检出冲突,尤其是存在身份验证差异时会直接导致构建失败。
解决方法
通过restoreArguments参数添加NuGet的--no-restore-submodules选项,即可阻止restore过程中自动检出子模块。修改后的任务配置如下:
- task: DotNetCoreCLI@2 displayName: "Restore" inputs: command: restore selectOrConfig: config nugetConfigPath: nuget.config workingDirectory: .. verbosityRestore: Normal restoreArguments: '--no-restore-submodules'
关于restoreArguments的说明
这个参数本质是传递额外命令行参数给dotnet restore命令,所有dotnet restore支持的命令行选项都可以在这里使用。除了--no-restore-submodules,常见可用选项还包括:
--force: 强制还原所有依赖,忽略已缓存的包--disable-parallel: 禁用并行还原依赖--configfile <PATH>: 指定NuGet配置文件(注:你已通过nugetConfigPath设置,无需重复添加)
内容的提问来源于stack exchange,提问作者Ed Williams
相关产品推荐
相关产品推荐

