azure - 为什么 NuGet 恢复任务必须与构建任务位于同一作业中?

标签 azure azure-devops nuget

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/

相关文章:

azure - AD B2C CompareClaims 引发内部服务器错误

nuget - 仅使用 Nuget.exe 打包 SQL 文件

azure - 机器人框架 : httpStatusCode": 504 getting Failed to send activity: bot timed out

Azure Cloud Shell Ansible 与 Windows 主机

c# - 如何从代码运行 Azure DevOps 管道?

azure - 如何从管道 Azure DevOps 访问私有(private)存储库?

azure - 我可以将 MSI token 用于 Azure DevOps REST API吗?

tfs - 如何在 nuget 包版本中添加 <release note> 节点?

visual-studio - Nuget-package 未添加包引用

Azure Durable编排功能ILogger输出两次日志