0

I am a bit stuck in here and might need some help to understand this process with azure pipeline.

I have this pipeline:

steps:

- task: DotNetCoreCLI@2
  displayName: 'DotNet - Restore'
  inputs:
    command: 'restore'
    projects: '**/*.csproj'
    noCache: true
    versioningScheme: 'off'
    vstsFeed: 'my-feed'
- task: DotNetCoreCLI@2
  displayName: 'DotNet - Pack'
  inputs:
    command: 'pack'
    packagesToPack: '**/*.csproj'
    versioningScheme: 'off'
- task: DotNetCoreCLI@2
  displayName: 'DotNet - Push'
  inputs:
    command: 'push'
    packagesToPush: '$(Build.ArtifactStagingDirectory)/*.nupkg'
    nuGetFeedType: 'internal'
    publishVstsFeed: 'my-feed'

This pipeline takes roughly 6mins to run, when I check the details of the pipeline, I see that the tasks that take the most are the restore and pack.

When I check the output of those task, I am pretty sure that the pipeline, is building and restoring in the first step, this:

- task: DotNetCoreCLI@2
  displayName: 'DotNet - Restore'
  inputs:
    command: 'restore'
    projects: '**/*.csproj'
    noCache: true
    versioningScheme: 'off'
    vstsFeed: 'my-feed'

and when I check the Pack I see the same thing

- task: DotNetCoreCLI@2
  displayName: 'DotNet - Pack'
  inputs:
    command: 'pack'
    packagesToPack: '**/*.csproj'
    versioningScheme: 'off'

I checked the azure documentation, but I couldn't find any explanation about the steps for pack steps and if it comes with a Restore.

Can anyone shade some light on this?..if I get rid of the Restore, the project will be Restored anyway as part of the pack?

I want to cut the build time of this pipeline.

Thank you so much for any help or explanation.

Nayden Van
  • 1,133
  • 1
  • 23
  • 70

1 Answers1

1

The documentation for dotnet pack clearly explains the behavior:

You don't have to run dotnet restore because it's run implicitly by all commands that require a restore to occur, such as dotnet new, dotnet build, dotnet run, dotnet test, dotnet publish, and dotnet pack. To disable implicit restore, use the --no-restore option.

Emphasis mine.

Daniel Mann
  • 57,011
  • 13
  • 100
  • 120
  • Uh that's amazing, I didn't saw that. so I can just get rid of the restore task and keep only the pack – Nayden Van Aug 19 '21 at 16:42
  • It makes sense to keep it when you have several commands. So if you have dotnet build, then test then pack it would be better to add dotnet restore in front ant then run others with `--no-restore` flag. – Krzysztof Madej Aug 19 '21 at 18:37
  • I tried to remove the restore task but the pipeline fail as it output it failed to restore the project. Which is weird because it should be part of the command pack. if I want to flag the `no-restore` in the pack pipeline, do I have to add it as an argument? – Nayden Van Aug 20 '21 at 08:13
  • @KrzysztofMadej I followed your advice and kept the restore and added the flag `--no-restore` to the pack task, but I don't see any improvement. Maybe you can help me to understand this bit. even if I add the flag, the project get compiled twice, one for each task and its a waste of time. how can I just pack from the previous task? because even if the `pack` command comes with a restore and build, if I get rid of the restore task, my pipeline fails. – Nayden Van Aug 20 '21 at 09:16
  • The reason it's failing on `pack` without `restore` is probably because you're using a custom feed: `vstsFeed: 'my-feed'`. Your `pack` is still restoring because the `arguments` property doesn't support the `pack` command: https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/build/dotnet-core-cli?view=azure-devops#arguments. You have to use a type of `custom` instead of `pack` if you want to pass in arguments. – Daniel Mann Aug 20 '21 at 15:18
  • You could also try adding `vstsFeed` to `pack` and omitting `restore` although I'm not sure that will work. – Daniel Mann Aug 20 '21 at 15:25