Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiline string in Azure Pipelines

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.

like image 415
spottedmahn Avatar asked Nov 12 '19 17:11

spottedmahn


3 Answers

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

like image 87
Leif Avatar answered Jan 01 '23 03:01

Leif


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.

like image 30
Leo Liu-MSFT Avatar answered Jan 01 '23 01:01

Leo Liu-MSFT


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'
like image 22
Shayki Abramczyk Avatar answered Jan 01 '23 02:01

Shayki Abramczyk