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.
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
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.
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'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With