【问题标题】:How to make the Nuget restore work faster?如何使 Nuget 恢复工作更快?
【发布时间】:2018-02-09 12:29:25
【问题描述】:

我们正在使用 VSTS 托管的构建服务器构建 CD 管道。恢复 Nuget 需要 3 分钟以上。这时间太多了。

我怎样才能让它运行得更快?有什么我们可以使用的缓存系统吗?

【问题讨论】:

标签: nuget azure-devops nuget-package nuget-package-restore azure-artifacts


【解决方案1】:

更新:缓存现已普遍可用 (docs)

Caching is currently on the feature pipeline,日期待定。同时,您可以使用 Upload Pipeline Artifact/Download Pipeline Artifact 任务将结果存储在您的 Azure DevOps 帐户中以加快/下载速度。

Work-in-progress can be tracked here

与此同时,Microsoft 1ES (one engineering system, internal organization) has released their internal solution that uses Universal Packages to store arbitrary packages in your Azure DevOps account。它非常快,因为它可以在以前的包之间同步增量。 There is a sample on how to configure your Azure Pipeline to store the NuGet package cache in your Sources Directory in order for the task to cache them.

variables:
  NUGET_PACKAGES: $(Build.SourcesDirectory)/packages
  keyfile: '**/*.csproj, **/packages.config, salt.txt'
  vstsFeed: 'feed name'

steps:
- task: 1ESLighthouseEng.PipelineArtifactCaching.RestoreCache@1
  displayName: 'Restore artifact'
  inputs:
    keyfile: $(keyfile)
    targetfolder: $(NUGET_PACKAGES)
    vstsFeed: $(vstsFeed)

【讨论】:

  • 不幸的是,新缓存的恢复速度非常慢,通常比直接重新下载依赖项要慢。
  • 问题一般是45000个小文件。除非您可以挂载驱动器映像,否则没有真正快速的方法来缓存这些混乱。挂载 vhd,恢复海量文件,卸载驱动器,缓存驱动器。
  • 这不是问题,因为对于一小部分较大的文件来说它仍然很慢,甚至与数据中心外的 CDN 下载相比通常也很慢。此外,Gradle Enterprise 等工具表明您可以有效地缓存大量小文件。但是,是的,缓存绝对应该是基于本地磁盘的,公共 cmet 在设计审查中提出,基于网络的缓存会足够慢,以至于几乎没有什么用处,而且确实如此。我不确定有哪些其他 CI/CD 提供商尝试过基于网络的缓存。
【解决方案2】:

在我的场景中,Nuget 还原在交互运行时运行得很快,但在通过 CD 管道 (Jenkins) 运行时非常很慢。将 revocation check mode 设置为 offline 将我的 Nuget 还原时间从 13 多分钟减少到 30 秒以下(我找到了这个解决方案 here

在运行 Nuget 还原之前,我在构建脚本中设置了一个环境变量:

  • SET NUGET_CERT_REVOCATION_MODE=offline

免责声明:关闭证书吊销会产生影响 - 请参阅link

【讨论】:

  • 这个环境变量完成了这项工作,谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多