0

Using Azure Pipelines, I have the following step in a job running on the windows-2022 vmImage:

- pwsh: |
    $config = "${{ parameters.buildConfiguration }}"
    $runtime = "${{ parameters.runtime }}"

    dotnet publish WebApp `
      --configuration $buildConfiguration `
      --runtime $runtime `
      --output publish `
      --self-contained true
  displayName: dotnet publish for ${{ parameters.runtime }}

This weirdly results in the following failure:

========================== Starting Command Output ===========================
"C:\Program Files\PowerShell\7\pwsh.exe" -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command ". 'D:\a\_temp\a3fb3cbf-4c5d-4ee6-b4a8-979fceec0fab.ps1'"
MSBuild version 17.3.1+2badb37d1 for .NET
MSBUILD : error MSB1008: Only one project can be specified.
    Full command line: 'C:\Program Files\dotnet\sdk\6.0.401\MSBuild.dll -maxcpucount -verbosity:m -restore -target:Publish -property:PublishDir=D:\a\1\s\publish -property:SelfContained=True -property:_CommandLineDefinedSelfContained=true -property:Configuration=--runtime WebApp linux-x64 -distributedlogger:Microsoft.DotNet.Tools.MSBuild.MSBuildLogger,C:\Program Files\dotnet\sdk\6.0.401\dotnet.dll*Microsoft.DotNet.Tools.MSBuild.MSBuildForwardingLogger,C:\Program Files\dotnet\sdk\6.0.401\dotnet.dll'
  Switches appended by response files:
Switch: linux-x64

What's concerning about the above information is the -property:Configuration=--runtime WebApp linux-x64 part. Looks like there's some weird parsing issue, perhaps. I tried putting the dotnet publish part all on one line (by removing the back-ticks) and I still get the same error. I tried many permutations of the inline script but had no success.

What makes this even weirder is if I add the bottom 3 new properties to the step:

- pwsh: |
    $config = "${{ parameters.buildConfiguration }}"
    $runtime = "${{ parameters.runtime }}"

    dotnet publish WebApp `
      --configuration $buildConfiguration `
      --runtime $runtime `
      --output publish `
      --self-contained true
  displayName: dotnet publish for ${{ parameters.runtime }}
  debugPreference: Continue
  verbosePreference: Continue
  informationPreference: Continue

I get the following errors in the "Run pipeline" GUI before I can even start a build:

/deploy/build_webapp.yml (Line: 49, Col: 9): Unexpected value 'debugPreference'
/deploy/build_webapp.yml (Line: 50, Col: 9): Unexpected value 'verbosePreference'
/deploy/build_webapp.yml (Line: 51, Col: 9): Unexpected value 'informationPreference'

enter image description here

This one isn't specifically related to the dotnet publish command failing, but it's just one more weird aspect of this. Using those Preference properties shouldn't cause a failure since they're clearly documented as supported with the pwsh task.

The only way I've been able to get dotnet publish working is by switching to the PowerShell@2 task and running the dotnet publish command in a file:

Publish.ps1:

param($config, $runtime)

dotnet publish WebApp `
  --configuration $config `
  --runtime $runtime `
  --output publish `
  --self-contained true

And in my pipeline YAML:

- task: PowerShell@2
  inputs:
    filePath: deploy/Publish.ps1
    arguments: ${{ parameters.buildConfiguration }} ${{ parameters.runtime }}

I'm completely stumped. At first, I thought that the inline pwsh task might have issues with the backtick characters. But that doesn't seem to be it. Why does the pwsh task not work as I expect?

6
  • 1
    You define a $config variable in your PS script but don't use it. That's not intended, I'd guess. Also, print the values of your variables before calling dotnet publish to verify the values are expected. Commented Oct 1, 2022 at 0:24
  • Do you have multiple projects in this directory? You're doing "dotnet publish WebApp" Try "dotnet publish .\WebApp.csproj", or whatever is your project file name. Commented Oct 1, 2022 at 0:31
  • Also, are you sure your first snippet is not an instance of steps.pwsh? Commented Oct 1, 2022 at 0:35
  • In the inline version you use $buildConfiguration which does not appeaer to be defined. Did you mean to use $config there? Commented Oct 1, 2022 at 17:15
  • Wow, how embarrassing. You're right, it was the fact that I was using $buildConfiguration instead of $config. What a mess, I spent hours on this and the error messages just weren't helping at all. I wish I knew a way to struggle less on this in the future. In this case all I needed was an extra pair of eyes... I'm not sure if I should delete this question (since it's misleading) or accept someone's comment as the answer. Commented Oct 3, 2022 at 14:29

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.