Windows Azure Web Sites Programmatic Web Deploy

I was setting up a continuous integration / deployment pipeline last night for my team at GovHack Perth and I had a lot of trouble getting the web deploy deployment working against an Azure Web Sites site.

I had downloaded the .publishsettings file and copied out the username, password and server to pass through to the .cmd file that is generated by MSBuild when creating a web deploy package. I do this because I create the package separately as part of the CI build and attach it as a build artifact and then separately do the deployment with msdeploy as another CI build step.

The problem I came across was that I kept getting the following error when running the deployment:

C:\Path\To\Project\obj\Release\Package>projectname.deploy.cmd /T /M:https://waws-prod-hk1-001.pu
blish.azurewebsites.windows.net:443/msdeploy.axd /U:$sitename /P:password /A:Basic
SetParameters from:
"C:\Path\To\Project\obj\Release\Package\projectname.SetParameters.xml"
You can change IIS Application Name, Physical path, connectionString
or other deploy parameters in the above file.
-------------------------------------------------------
Start executing msdeploy.exe
-------------------------------------------------------
"C:\Program Files\IIS\Microsoft Web Deploy V3\msdeploy.exe" -source:package='C:
\Path\To\Project\obj\Release\Package\projectname.zip' -dest:auto,computerName="https://waws-prod
-hk1-001.publish.azurewebsites.windows.net:443/msdeploy.axd",userName="$sitename"
,password="password",authtyp
e="Basic",includeAcls="False" -verb:sync -disableLink:AppPoolExtension -disableL
ink:ContentExtension -disableLink:CertificateExtension -setParamFile:"C:\Path\To\Project\obj
\Release\Package\projectname.SetParameters.xml" -whatif
Info: Using ID '744a18b1-51c2-4d05-a674-6c407a7f80c5' for connections to the rem
ote server.
Error Code: ERROR_USER_UNAUTHORIZED
More Information: Connected to the remote computer ("waws-prod-hk1-001.publish.a
zurewebsites.windows.net") using the Web Management Service, but could not autho
rize. Make sure that you are using the correct user name and password, that the
site you are connecting to exists, and that the credentials represent a user who
has permissions to access the site. Learn more at: http://go.microsoft.com/fwl
ink/?LinkId=221672#ERROR_USER_UNAUTHORIZED.
Error: The remote server returned an error: (401) Unauthorized.
Error count: 1.

It turns out the problem was I needed to include the ?site=sitename parameter in the msdeploy destination otherwise (I assume) the load balancer on the publish server can’t authenticate your username and password properly. This meant I needed to switch to using msdeploy.exe directly like so:

"C:\Program Files\IIS\Microsoft Web Deploy V3\msdeploy.exe" -source:package='projectname.zip' -dest:auto,computerName="https://waws-prod-hk1-001.publish.azurewebsites.windows.net:443/msdeploy.axd?site=sitename",userName="$sitename",password="password",authtype="Basic",includeAcls="False" -verb:sync -disableLink:AppPoolExtension -disableLink:ContentExtension -disableLink:CertificateExtension -setParamFile:"projectname.SetParameters.xml"

Hopefully this post helps other people stuck in the same situation (I couldn’t find anything on Google to help with this)!

6 Replies to “Windows Azure Web Sites Programmatic Web Deploy”

  1. Hi Robert,

    Thanks for taking the time to blog this – it came in really handy when we setup our CI pipeline in Bamboo.

    Here’s another gotcha that I hit that I thought I would post here for others to see.

    When we were dunning msdeploy, we were getting an “ERROR_USER_NOT_AUTHORIZED_FOR_IISAPP” error code.

    I spent a while looking into it, and eventually worked out that this was being caused by the “projectname.SetParameters.xml” file.

    In our SetParameters.xml file, we had a line that looked like this:

    <setParameter name="IIS Web Application Name" value="Default Web Site/ProjectName_deploy" />

    This obviously wont work with Azure websites as you cannot specify what the name of the application should be – it should have already been setup when you created the site.

    We worked around this by putting in an additional script task between the msbuild task and the msdeploy task. This script just does a simple string replace on the duff IIS Web Application Name and replaces it with the correct Azure name.

    Thanks again!

    Ed

    1. It is also possible to override the default SetParameters.xml values at the command line:
      -setParam:name=”IIS Web Application Name”,value=webappname

  2. Great post, this saved me some trouble. Quick question, utilizing the default deployment cmd file which is created by MSBuild, how would you pass in the site= parameter. I can get it running from the cmd line, however, when trying to pass this parameter into the default .cmd file that is created, it doesn’t like the site= after the /M:

    1. You can’t add the ?site to the M: parameter (as you have discovered).

      Instead, you need the value to be in the SetParameters.xml file like what the commenter above you had.

      You should be able to get MSBuild to generate the right value for you if you either set it manually/programmatically or include the following in your .csproj file:

      <DeployIisAppPath>SiteName</DeployIisAppPath>

      Note: if you put that in your .csproj then you probably want to have the same site name in all environments, which is a good practice anyway.

Leave a Reply

Your email address will not be published. Required fields are marked *