11

Can I use a multiline YAML string in Azure Pipelines?

Using the ASP.NET Core (.NET Framework) template I tried multilining the msbuildArgs but that didn't work.

- task: VSBuild@1
  inputs:
    solution: '$(solution)'
    msbuildArgs: >
       '/p:DeployOnBuild=true /p:WebPublishMethod=Package'
       '/p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true'
       '/p:DesktopBuildPackageLocation="$(build.artifactStagingDirectory)\WebApp.zip"'
       '/p:DeployIisAppPath="Default Web Site"'
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

MSBUILD : error MSB1008: Only one project can be specified.
Switch: '/p:DeployOnBuild=true


Reviewing the string reference documentation I don't see any about this topic.

spottedmahn
  • 13,373
  • 8
  • 95
  • 158

3 Answers3

22

I always use the YAML block chomping operator like this

msbuildArgs: >-
  /p:DeployOnBuild=true
  /p:WebPublishMethod=Package
  /p:PackageAsSingleFile=true
  /p:SkipInvalidConfigurations=true
  /p:DesktopBuildPackageLocation="$(build.artifactStagingDirectory)\WebApp.zip"
  /p:DeployIisAppPath="Default Web Site"

Works well and makes things crystal clear and neat

Leif
  • 1,059
  • 10
  • 17
  • Well for my AzureCLI task in YAML, it required arguments like this [arguments: '-param XYZ' ] and so when I broke it up it was similar to yours except that I did not put minus sign after greater than sign and remove the single quotes as well. Note that square brackets are just for clarity here. – Varun Sharma Nov 18 '21 at 06:05
4

You can just put ' in the start and the end of the msbuildArgs:

- task: VSBuild@1
  displayName: 'Build solution **\*.sln'
  inputs:
    vsVersion: latest
    msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package 
    /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true'
spottedmahn
  • 13,373
  • 8
  • 95
  • 158
Shayki Abramczyk
  • 30,710
  • 15
  • 70
  • 94
3

Multiline string in Azure Pipelines

Shayki Abramczyk pointed out the key to the this error.

Just put one ' in the start and the end of the msbuildArgs without having to configure for each MSBuild argument

As test, following YAML work for me:

- task: VSBuild@1
  displayName: 'Build solution YourSolution'
  inputs:
    solution: $(solution)
    msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:DesktopBuildPackageLocation="$(build.artifactStagingDirectory)\WebApp.zip" /p:DeployIisAppPath="Default Web Site"'
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

Note: The variable $(solution) should point to a specific solution .sln or project .csproj file instead of **\*.sln. If you have one more solution in your repo, you may get the error Only one project can be specified.

Update:

but I don’t want super long run-on line as in your answer provided. I want to split across multiple lines!

If you do not want to super long run-on line as in MSBuild arguments, you could split them directly, but pay attention to indentation, like:

- task: VSBuild@1
  displayName: 'Build solution YourSolution'
  inputs:
    solution: $(solution)
    msbuildArgs: '/p:DeployOnBuild=true
                  /p:WebPublishMethod=Package 
                  /p:PackageAsSingleFile=true 
                  /p:SkipInvalidConfigurations=true 
                  /p:DesktopBuildPackageLocation="$(build.artifactStagingDirectory)\WebApp.zip" 
                  /p:DeployIisAppPath="Default Web Site"'
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

As test, it works fine.

Hope this helps.

spottedmahn
  • 13,373
  • 8
  • 95
  • 158
Leo Liu-MSFT
  • 62,538
  • 8
  • 91
  • 107
  • 1
    Hi Leo Liu - appreciate the answer but I don’t want super long run-on line as in your answer provided. I want to split across multiple lines! – spottedmahn Nov 18 '19 at 02:06
  • 1
    @spottedmahn, Got you! Let me check if it can be divided into multiple lines, will let you know when I have the result. – Leo Liu-MSFT Nov 18 '19 at 02:11
  • 1
    @spottedmahn, You can split them directly, but pay attention to indentation. Check my updated answer for some more details. – Leo Liu-MSFT Nov 18 '19 at 03:11