Search code examples
azureazure-web-app-servicemsdeploy

Deploying a web application to an Azure App Service using MSDeploy


I'm having a lot of trouble deploying my web application to an Azure App Service using MSDeploy. What are the command line arguments I need to use?


Solution

  • MSDeploy is a little finicky with the way it accepts parameters. First, the command will need the username and password for your App Service. This can be found by using the Azure CLI in PowerShell like so:

    $publishProfile = az webapp deployment list-publishing-profiles --resource-group <ResourceGroupName> --name <WebAppName> --query "[?publishMethod=='MSDeploy']" | ConvertFrom-Json
    

    This will place the username and password into the $publishProfile variable for use with MSDeploy later.

    Next, if the path to the source published web site has spaces in it and PowerShell is being used, it will need to be converted to its equivalent short name syntax. If this is not done, MSDeploy will throw meaningless exceptions like the following that are painful to diagnose.

    Error Code: ERROR_PROVIDER_NOT_FOUND More Information: The provider 'dirPath=' could not be found. Learn more at: https://go.microsoft.com/fwlink/?LinkId=221672#ERROR_PROVIDER_NOT_FOUND. at Microsoft.Web.Deployment.DeploymentProviderSettingCollection..ctor(String factoryName) at Microsoft.Web.Deployment.DeploymentProviderOptions..ctor(String factoryName) at MSDeploy.MSDeploy.GetObjectParameters(Dictionary`2 parameters, Boolean isDestination, DeploymentBaseOptions& retbaseOptions, DeploymentProviderOptions& retproviderOptions) at MSDeploy.MSDeploy.ExecuteWorker() at MSDeploy.MSDeploy.Execute() at MSDeploy.MSDeploy.Main(String[] unusedArgs) Error count: 1.

    To convert the path to its short name equivalent, use the following command:

    $shortPath = (New-Object -ComObject Scripting.FileSystemObject).GetFolder(".\Publish").ShortPath
    

    And finally, here's the command to run MSDeploy and deploy the web application to Azure. In order to use the command below, the $webAppName variable will need to be defined.

    $webAppName = "MyWebApp"
    &"C:\Program Files\IIS\Microsoft Web Deploy V3\msdeploy.exe" -verb:sync -source:dirPath="$shortPath",includeAcls=false -dest:dirpath=D:\home\site\wwwroot,ComputerName="https://$webAppName.scm.azurewebsites.net/msdeploy.axd?site=$($webAppName)",UserName=$($publishProfile.userName),Password=$($publishProfile.userPWD),AuthType='Basic' -verbose -debug
    

    The command should return output similar to the following:

    Info: Using ID 'd5e5eb3d-...' for connections to the remote server.
    Verbose: Pre-authenticating to remote agent URL 'https://webappname.scm.azurewebsites.net/msdeploy.axd?site=webappname' as '$webappname'.
    Verbose: Performing synchronization pass #1.
    Verbose: Pre-authenticating to remote agent URL 'https://webappname.scm.azurewebsites.net/msdeploy.axd?site=webappname' as '$webappname'.
    Verbose: Received response from agent (HTTP status 'OK').
    Info: Adding directory (D:\home\site\wwwroot\cs).
    Info: Adding directory (D:\home\site\wwwroot\de).
    Info: Adding directory (D:\home\site\wwwroot\es).
    Info: Adding directory (D:\home\site\wwwroot\fr).
    Info: Deleting file (D:\home\site\wwwroot\hostingstart.html).
    Info: Adding directory (D:\home\site\wwwroot\it).
    Info: Adding directory (D:\home\site\wwwroot\ja).
    Info: Adding directory (D:\home\site\wwwroot\ko).
    Info: Adding directory (D:\home\site\wwwroot\pl).
    Info: Adding directory (D:\home\site\wwwroot\pt-BR).
    Info: Adding directory (D:\home\site\wwwroot\ru).
    Info: Adding directory (D:\home\site\wwwroot\runtimes).
    Info: Adding directory (D:\home\site\wwwroot\runtimes\unix).
    Info: Adding directory (D:\home\site\wwwroot\runtimes\unix\lib).
    Info: Adding directory (D:\home\site\wwwroot\runtimes\unix\lib\netcoreapp2.0).
    Info: Adding directory (D:\home\site\wwwroot\runtimes\unix\lib\netcoreapp2.1).
    Info: Adding directory (D:\home\site\wwwroot\runtimes\win).
    Info: Adding directory (D:\home\site\wwwroot\runtimes\win\lib).
    Info: Adding directory (D:\home\site\wwwroot\runtimes\win\lib\netcoreapp2.0).
    Info: Adding directory (D:\home\site\wwwroot\runtimes\win\lib\netcoreapp2.1).
    Info: Adding directory (D:\home\site\wwwroot\runtimes\win\lib\netstandard2.0).
    Info: Adding directory (D:\home\site\wwwroot\runtimes\win-arm64).
    Info: Adding directory (D:\home\site\wwwroot\runtimes\win-arm64\native).
    Info: Adding directory (D:\home\site\wwwroot\runtimes\win-x64).
    Info: Adding directory (D:\home\site\wwwroot\runtimes\win-x64\native).
    Info: Adding directory (D:\home\site\wwwroot\runtimes\win-x86).
    Info: Adding directory (D:\home\site\wwwroot\runtimes\win-x86\native).
    Info: Adding directory (D:\home\site\wwwroot\tr).
    Info: Adding directory (D:\home\site\wwwroot\zh-Hans).
    Info: Adding directory (D:\home\site\wwwroot\zh-Hant).
    Verbose: The dependency check 'DependencyCheckInUse' found no issues.
    Verbose: The current synchronization pass is missing stream content for 201 objects.
    Info: Using ID '1f1ab053-88c6-40a2-90e4-5347157542e6' for connections to the remote server.
    Verbose: Performing synchronization pass #2.
    Verbose: Pre-authenticating to remote agent URL 'https://webappname.scm.azurewebsites.net/msdeploy.axd?site=webappname' as '$webappname'.
    ...
    Verbose: The HTTP connection (ID='1f1ab053-88c6-40a2-90e4-5347157542e6', type ='GetTraceStatus') is being kept alive while the request is processed.
    Verbose: Received response from agent (HTTP status 'OK').
    ...
    Verbose: The dependency check 'DependencyCheckInUse' found no issues.
    Verbose: The synchronization completed in 2 pass(es).
    Total changes: 231 (230 added, 1 deleted, 0 updated, 0 parameters changed, 44498979 bytes copied)