Search code examples
powershellazureazure-web-app-servicemsdeployazure-powershell

Azure Web App: Delete all files before publish


When publishing to our Azure Web App using the following Powershell script, we often have issues whereby files from the previous publish cause runtime errors.

param($websiteName, $packOutput)

$website = Get-AzureWebsite -Name $websiteName

# get the scm url to use with MSDeploy.  By default this will be the second in the array
$msdeployurl = $website.EnabledHostNames[1]

$publishProperties = @{'WebPublishMethod'='MSDeploy';
                        'MSDeployServiceUrl'=$msdeployurl;
                        'DeployIisAppPath'=$website.Name;
                        'Username'=$website.PublishingUsername;
                        'Password'=$website.PublishingPassword}

Write-Output "Stopping web app..."
Stop-AzureWebsite -Name $websiteName

Write-Output "Publishing web app..."
$publishScript = "${env:ProgramFiles(x86)}\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\Web Tools\Publish\Scripts\default-publish.ps1"

Write-Output "Starting web app..."
Start-AzureWebsite -Name $websiteName

. $publishScript -publishProperties $publishProperties  -packOutput $packOutput

How can I delete all the existing files before the publish?

Note that we cannot use slots because this requires Standard instances, which are too expensive for our CI environment.


Solution

  • try adding:

    'SkipExtraFilesOnServer'=$false;
    

    to your $publishProperties that should disable the DoNotDeleteRule MSDeploy uses to keep extra files around.