在Azure DevOps中,当NuGet恢复任务在同一个作业中运行时 strong> 作为 VS Build 任务一切正常:
pool:
vmImage: 'windows-latest'
jobs:
- job:
steps:
- task: NuGetToolInstaller@1
- task: NuGetCommand@2
inputs:
restoreSolution: 'Framer/Framer.sln'
- task: VSBuild@1
inputs:
solution: 'Framer/Framer.sln'
platform: 'Any CPU'
configuration: 'Release'
但是当它们处于 2 个不同的工作中时,VS 构建会失败:
pool:
vmImage: 'windows-latest'
jobs:
- job:
steps:
- task: NuGetToolInstaller@1
- task: NuGetCommand@2
inputs:
restoreSolution: 'Framer/Framer.sln'
- job:
steps:
- task: VSBuild@1
inputs:
solution: 'Framer/Framer.sln'
platform: 'Any CPU'
configuration: 'Release'
有错误:
Error NETSDK1004: Assets file 'D:\a\1\s\Framer\FramerCLI\obj\project.assets.json' not found. Run a NuGet package restore to generate this file.
就像恢复任务没有运行一样。
问题是什么?
每个作业都在自己的“上下文”中运行吗?
但在日志中我看到两个任务的根路径 D:\a\1\s\
完全相同,也许两者之间有一些清理?
有没有办法让它们同时运行两项工作? (不过不确定这是否是一个好主意)
最佳答案
从您共享的 YAML 中,我们可以看到您正在使用 Microsoft 托管的 windows-latest
代理来运行管道作业。
基于文档“Microsoft-hosted agents”的声明:
Each time you run a pipeline, you get a fresh virtual machine for each job in the pipeline. The virtual machine is discarded after one job (which means any change that a job makes to the virtual machine file system, such as checking out code, will be unavailable to the next job).
这意味着,每次在 Microsoft 托管的代理上运行管道作业时,每个作业都会获得一个新的虚拟机。换句话说,每个作业可以在与其他作业不同的虚拟机上运行,即使在同一管道中运行。通常,作业完成后,该作业的虚拟机将被丢弃。因此,该作业对虚拟机所做的所有更改也将与虚拟机一起被丢弃。
因此,在 Microsoft 托管的代理上运行时,您需要还原每个作业中的包。
如果每次需要恢复的包体积较大且不经常更新,可以考虑使用 Cache task减少恢复包的时间并提高构建性能。
关于azure - 为什么 NuGet 恢复任务必须与构建任务位于同一作业中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/77251758/