VSTS - 部署前使应用脱机

VSTS - Take app offline before deployment

我在使用 VSTS 持续部署到 Azure 时遇到了这个问题

Web Deploy cannot modify the file 'XXX' on the destination because it is locked by an external process

this thread 中提供的解决方案是在 azure 中手动重启我的应用程序,但是他没有使用 VSTS,问题是 2 年前提出的,这个问题是否已在当前 VSTS 上修复,如果是,我想知道如何解决,因为我遇到了与上面提到的 link 相同的问题。

谢谢

您可以按照此处的说明使用 "EnableMSDeployAppOffline" 功能在部署前将您的应用设置为离线:Web publishing updates for app offline and usechecksum

如果还是不行,你也可以创建一个PowerShell脚本如下来停止应用,部署然后重启应用:

    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"

. $publishScript -publishProperties $publishProperties  -packOutput $packOutput

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

PowerShell 脚本来自:Build and Deploy your ASP.NET 5 Application to an Azure Web App

基本上你需要停止 - 部署 - 重启。

你有很多选择,但更简单的是:

1- 扩展:Azure 应用服务 - 启动和停止 你可以尝试扩展 "Azure App Services - Start and Stop" https://marketplace.visualstudio.com/items?itemName=rbengtsson.appservices-start-stop

2- AzureCLI 任务 从构建或部署 windows 添加 am Azure CLI 任务(目前处于预览状态)

部署任务前加一个 使用内联脚本:

azure webapp stop --resource-group NAME_OF_YOUR_RESOURCE_GROUP --name WEBAPP_NAME

部署任务后再添加一个 使用内联脚本:

azure webapp start --resource-group NAME_OF_YOUR_RESOURCE_GROUP --name WEBAPP_NAME

希望对你有所帮助。