12

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
  • 14,823
  • 13
  • 108
  • 178

3 Answers3

25

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,129
  • 1
  • 12
  • 18
  • 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
5

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
  • 14,823
  • 13
  • 108
  • 178
Shayki Abramczyk
  • 36,824
  • 16
  • 89
  • 114
5

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
  • 14,823
  • 13
  • 108
  • 178
Leo Liu
  • 71,098
  • 10
  • 114
  • 135
  • 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 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 Nov 18 '19 at 03:11