5

I'm trying to build aspnetcore artifact for a solution with multiple web projects inside. Default netcore publish task has checkbox "Publish Web Projects" that finds all projects containing web.config or wwwroot folders, but my WebApi projects doesn't need them at all. You can disable this checkbox and provide paths to projects you want to publish. Each project must be provided in separate line.

So, if I edit this setting in task properties window, everything is ok, cause there is multiline editor that behaves as expected. But I want to move list of projects to variables, were all other configuration is stored. However variable's editor is singleline.

I've decided to put project names in variable with ";" delimiter and write powershell task that properly constructs paths for publish task:

$projects = '$(PublishProjects)'
$result = ( $projects.Split(@(';'), [System.StringSplitOptions]::RemoveEmptyEntries) | %{ ('**\' + $_.Trim() + '.csproj') } ) -join "`n"
Write-Host "##vso[task.setvariable variable=PublishProjectsPath]$result"

Unfortunately this results in setting PublishProjectsPath`s value to only first project, cause all project paths except first one are printed on their own line without ##vso... and so azure ignores them effectively.

Is there any way to set pipeline variable from script correctly? I cannot use azure-pipelines.yml cause azure doesn't support gitlab :(

2 Answers2

0

Set variable in script with string value that contains newline

For this issue , I am afraid this is currently not support in azure devops. Although dotnet publish task has the textboxes that support multiple line content , but currently does not support multi-line string as the value of a variable.

Until now, in our official feature suggestion for Azure Devops forum, there has been a such suggestion exist in it: https://developercommunity.visualstudio.com/idea/365667/multiple-lines-variable-in-build-and-release.html.

You could vote that suggestion ticket and share your comment there,the product team would provide the updates if they view it. Anyone interested in this can vote for it and track it.

Hugh Lin
  • 17,829
  • 2
  • 21
  • 25
-1

Yous set the variable as job-scoped.

You need to set a multi job output variable with ##vso[task.setvariable variable=myOutputVar;isOutput=true]

Troopers
  • 5,127
  • 1
  • 37
  • 64