0

I have the following build pipeline task:

  - task: NuGetCommand@2
    displayName: 'Pack CodingStyles.nuspec'
    inputs:
      command: 'pack'
      packagesToPack: 'src\CodingStyles\CodingStyles.nuspec'
      packDestination: 'src\CodingStyles\bin'
      versioningScheme: 'off'
      buildProperties: '-NoDefaultExcludes -Version $(Build_Major).$(Build_Minor).$(Build_Patch)'

However, if the variable $IsPreRelease is true, I want to add another build property as well:

buildProperties: '-NoDefaultExcludes -Version $(Build_Major).$(Build_Minor).$(Build_Patch) -Suffix beta'

A few thoughts on how to do this:

  1. I could have two different versions of this task, each with a condition: based on the variable. This would probably work, but it's quite redundant since everything else is the same.
  2. Run a Powershell task instead of the NuGetCommand task, and build my command line dynamically.

Any options I'm missing?

1 Answer 1

2

You are missing one option:

  - task: NuGetCommand@2
    displayName: 'Pack CodingStyles.nuspec'
    inputs:
      command: 'pack'
      packagesToPack: 'src\CodingStyles\CodingStyles.nuspec'
      packDestination: 'src\CodingStyles\bin'
      versioningScheme: 'off'
      ${{ if ne(variables['IsPreRelease'], 'true') }}:
        buildProperties: '-NoDefaultExcludes -Version $(Build_Major).$(Build_Minor).$(Build_Patch)'
      ${{ if eq(variables['IsPreRelease'], 'true') }}:
        buildProperties: '-NoDefaultExcludes -Version $(Build_Major).$(Build_Minor).$(Build_Patch) -Suffix beta'

enter image description here

Sign up to request clarification or add additional context in comments.

3 Comments

Unfortunately DevOps doesn't let you repeat the same key twice..
Are you sure? I checked and you can save and run this. I notice some highlighting mentioning about duplication but this is display issue. All is fine with this snippet.
Oh if it's just a display error which I can ignore, then we should be good.. I'll try it out!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.