The Issue

I have been recently refreshing a GitHub end-to-end demo I use for talks and workshops that I had not looked at for a while. It shows how legacy code bases can be deployed with GitHub Actions and Azure App Services. The demo uses MSDeploy to deploy a ASP.NET web application to Azure App Services. The MSDeploy package is created as part of the GitHub Action workflow.

The workflow uses a PowerShell script to do the deployment using the following:

- name: 'Deploy web site with MSDeploy'
  run: |
    $publishProfile = az webapp deployment list-publishing-profiles --resource-group ${{ vars.AzureResourceGroup}} --name ${{ secrets.Sitename }} --query "[?publishMethod=='MSDeploy']" --subscription "${{ secrets.AZURESUBSCRIPTION}}" | convertfrom-json
    $shortPath = resolve-path ./webdeploy
    & "C:\Program Files\IIS\Microsoft Web Deploy V3\msdeploy.exe" -verb:sync -source:package="$shortpath\FabrikamFiber.Web.zip" -setParamFile:"$shortpath\FabrikamFiber.Web.SetParameters.xml" -dest:auto,ComputerName="https://$($publishProfile.msdeploySite).scm.azurewebsites.net/msdeploy.axd?site=$($publishProfile.msdeploySite)",UserName=$($publishProfile.userName),Password=$($publishProfile.userPWD),AuthType='Basic' -verbose -debug -disableLink:AppPoolExtension -disableLink:ContentExtension -disableLink:CertificateExtension
  shell: pwsh

When I last used this demo, over a year ago, it worked fine. However, when I tried to run it again, I found that the MSDeploy was failing with the following error:

Microsoft.Web.Deployment.DeploymentException: Unrecognized argument ‘"-dest:auto,ComputerName=“https://$($publishProfile.msdeploySite).scm.azurewebsites.net/msdeploy.axd?site=$($publishProfile.msdeploySite)",UserName=$($publishProfile.userName),***‘Basic’”’. All arguments must begin with “-”.

The Solution

The difference between when this workflow last ran and now is that the Powershell Core version used in the GitHub Action has been updated from 6 to 7. It appears the token replacement in the -dest parameter is not working as expected in Powershell 7, though it work for Powershell 6.

Once I altered it to the following, putting the whole dest parameter in quotes, it worked:

- name: 'Deploy web site with MSDeploy'
  run: |
    $publishProfile = az webapp deployment list-publishing-profiles --resource-group ${{ vars.AzureResourceGroup}} --name ${{ secrets.Sitename }} --query "[?publishMethod=='MSDeploy']" --subscription "${{ secrets.AZURESUBSCRIPTION}}" | convertfrom-json
    $shortPath = resolve-path ./webdeploy
    & "C:\Program Files\IIS\Microsoft Web Deploy V3\msdeploy.exe" -verb:sync -source:package="$shortpath\FabrikamFiber.Web.zip" -setParamFile:"$shortpath\FabrikamFiber.Web.SetParameters.xml" -dest:"auto,ComputerName=https://$($publishProfile.msdeploySite).scm.azurewebsites.net/msdeploy.axd?site=$($publishProfile.msdeploySite),UserName=$($publishProfile.userName),Password=$($publishProfile.userPWD),AuthType='Basic'" -verbose -debug -disableLink:AppPoolExtension -disableLink:ContentExtension -disableLink:CertificateExtension
  shell: pwsh