Azure Web App:发布前删除所有文件

Azure Web App: Delete all files before publish

使用以下 Powershell 脚本发布到我们的 Azure Web 应用程序时,我们经常会遇到问题,之前发布的文件会导致运行时错误。

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

如何在发布前删除所有现有文件?

请注意,我们不能使用插槽,因为这需要标准实例,这对于我们的 CI 环境来说太昂贵了。

尝试添加:

'SkipExtraFilesOnServer'=$false;

你的 $publishProperties 应该禁用 DoNotDeleteRule MSDeploy 用来保留额外文件。