如何使用缓存任务缓存 Azure Pipelines 中所有项目的 nuget 包

How to cache nuget packages for all projects in Azure Pipelines using Cache task

我正在使用以下步骤执行解决方案级缓存:

- task: Cache@2
  inputs:
    key: 'nuget | "$(Agent.OS)" | $(Build.SourcesDirectory)/**/packages.lock.json'
    restoreKeys: |
       nuget | "$(Agent.OS)"
       nuget
    path: $(NUGET_PACKAGES)
  displayName: Cache NuGet packages    

- task: DotNetCoreCLI@2
  displayName: 'dotnet restore using package.lock.json'
  inputs:
    command: 'restore'
    restoreArguments: '--locked-mode'
    feedsToUse: 'config'
    nugetConfigPath: 'nuget.config'

然而,在 Post-job: Cache NuGet packages 中有警告:

##[warning]The given cache key has changed in its resolved value between restore and save steps

我意识到这是因为锁定文件也复制到输出目录 */bin/release/net5.0/packages.lock.json 解析密钥时选择了文件。

我该如何解决这个问题?

已通过在键中使用以下模式修复:

key: 'nuget | "$(Agent.OS)" | **/packages.lock.json,!**/bin/**,!**/obj/**'