You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azure Pipeline中DotNet Pack步骤是否包含Restore操作?如何优化构建耗时

Optimizing Azure Pipeline: Eliminate Duplicate Restore in DotNet Pack

Great question—this is a common optimization point for .NET pipelines, so let’s break this down clearly for you.

Short Answer

Yes, the pack command in the DotNetCoreCLI@2 task automatically runs a restore by default if your project dependencies haven’t already been resolved. You can safely remove your standalone DotNet - Restore task to eliminate redundant work and cut down your pipeline runtime.

Why You’re Seeing Duplicate Work

The native .NET CLI dotnet pack command includes implicit restore logic: if your project’s dependencies aren’t already present (from a prior restore or build), it will automatically trigger dotnet restore before proceeding to package your project. The Azure Pipeline task is just a wrapper around this CLI behavior, which explains why both your Restore and Pack steps were performing identical dependency resolution and build operations.

Optimized Pipeline Configuration

Here’s how to adjust your YAML to remove the duplicate restore while retaining your original settings:

steps:
- task: DotNetCoreCLI@2
  displayName: 'DotNet - Pack'
  inputs:
    command: 'pack'
    packagesToPack: '**/*.csproj'
    versioningScheme: 'off'
    noCache: true # Keeps your original "no cache" restore behavior
- task: DotNetCoreCLI@2
  displayName: 'DotNet - Push'
  inputs:
    command: 'push'
    packagesToPush: '$(Build.ArtifactStagingDirectory)/*.nupkg'
    nuGetFeedType: 'internal'
    publishVstsFeed: 'my-feed'

Additional Tips

  • If you ever need to explicitly skip the restore in the Pack step (for example, if you’re restoring dependencies via a custom mechanism), you can add restore: false to the Pack task’s inputs. But for your use case, letting Pack handle the restore directly is the cleanest, most efficient approach.
  • This change should significantly reduce your pipeline runtime by removing the redundant restore and build operations that were running twice.

内容的提问来源于stack exchange,提问作者Nayden Van

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.30 04:57:30