在 Azure 应用服务和 Visual Studio 中自动化应用离线
Automatize App Offline in Azure App Service and Visual Studio
我想制作 App_Offline.htm 自定义和可更新我正在使用 MSDeploy 以便从 Azure Pipeline 和 Visual Studio 2019 发布。Publish Works 支持两者。我的 Web 项目在 .Net Core 2.2
我的问题是我想使用 MSDeploy 使应用程序脱机,发布前和删除 app_offline.htm 发布后。目前,我启用 MSDeployAppOffline,它显示秒数的默认“维护中”。直到 App_offline.htm 在应用服务中上传。然后我使用 Kudu 在线删除它。
后来我决定使用 MSDeploy CMDLine 远程添加和删除文件 app_offline.htm、beforePublish 和 AfterPublish ... 这也有效,我必须在发布管道中以纯文本形式保存我的密码,并且在 Visual Studio 中,所有方式都是“批处理脚本、PowerShell 脚本 ...”。
我的发布资料
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<WebPublishMethod>MSDeploy</WebPublishMethod>
<PublishProvider>AzureWebSite</PublishProvider>
<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
<LastUsedPlatform>Any CPU</LastUsedPlatform>
<SiteUrlToLaunchAfterPublish>mySiteUrl</SiteUrlToLaunchAfterPublish>
<LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
<ExcludeApp_Data>False</ExcludeApp_Data>
<ProjectGuid>GUID</ProjectGuid>
<MSDeployServiceURL>myapp.scm.azurewebsites.net:443</MSDeployServiceURL>
<DeployIisAppPath>increditing-preview</DeployIisAppPath>
<RemoteSitePhysicalPath />
<SkipExtraFilesOnServer>True</SkipExtraFilesOnServer>
<MSDeployPublishMethod>WMSVC</MSDeployPublishMethod>
<EnableMSDeployBackup>True</EnableMSDeployBackup>
<UserName>$myapp</UserName>
<_SavePWD>True</_SavePWD>
<_DestinationType>AzureWebSite</_DestinationType>
<EnableMSDeployAppOffline>true</EnableMSDeployAppOffline>
<MSDeployUseChecksum>true</MSDeployUseChecksum>
<MSDeployPath Condition="'$(MSDeployPath)'==''">
$(Registry:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\IISExtensions\MSDeploy@InstallPath)</MSDeployPath>
<MSDeployExe Condition=" '$(MSDeployExe)'=='' ">$(MSDeployPath)msdeploy.exe</MSDeployExe>
<DeleteCMD>
"$(MSDeployExe)" -verb:delete -dest:contentPath="$(DeployIisAppPath)/App_offline.htm",ComputerName="https://$(DeployIisAppPath).scm.azurewebsites.net/msdeploy.axd?site=$(DeployIisAppPath)",UserName="$(UserName)",Password="Password",IncludeAcls='False',AuthType='Basic'
</DeleteCMD>
</PropertyGroup>
<Target Name="CustomActionsAfterPublish" AfterTargets="AfterPublish">
<PropertyGroup>
</PropertyGroup>
<Message Text="Inside AfterPublish" Importance="high" />
<!-- MSDeploy does not work -->
<!--<MSDeploy Verb="delete"
Source="@(MsDeploySourceProviderSetting)"
Destination="contentPath=myapp/App_Offline.htm,computername=$(MsDeployServiceUrl)"
AllowUntrusted="$(AllowUntrustedCertificate)"
UseChecksum="$(MSDeployUseChecksum)"
UserAgent="$(_MSDeployUserAgent)"
ExePath="$(MSDeployPath)" />-->
<!-- Executing this command I have to use my Password in Pain Text -->
<Exec Command="$(DeleteCMD)" ></Exec>
</Target>
</Project>
https://github.com/projectkudu/kudu/issues/2949
为了避免 Kudu 问题,我所要做的就是:
在我的 Azure 应用服务中添加应用程序设置
并将 true 添加到我的发布配置文件中。
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<WebPublishMethod>MSDeploy</WebPublishMethod>
<PublishProvider>AzureWebSite</PublishProvider>
<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
<LastUsedPlatform>Any CPU</LastUsedPlatform>
<SiteUrlToLaunchAfterPublish>mySiteUrl</SiteUrlToLaunchAfterPublish>
<LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
<ExcludeApp_Data>False</ExcludeApp_Data>
<ProjectGuid>GUID</ProjectGuid>
<MSDeployServiceURL>myapp.scm.azurewebsites.net:443</MSDeployServiceURL>
<DeployIisAppPath>increditing-preview</DeployIisAppPath>
<RemoteSitePhysicalPath />
<SkipExtraFilesOnServer>True</SkipExtraFilesOnServer>
<MSDeployPublishMethod>WMSVC</MSDeployPublishMethod>
<EnableMSDeployBackup>True</EnableMSDeployBackup>
<UserName>$myapp</UserName>
<_SavePWD>True</_SavePWD>
<_DestinationType>AzureWebSite</_DestinationType>
/// EnableMSDeployAppOffline
<EnableMSDeployAppOffline>true</EnableMSDeployAppOffline>
<MSDeployUseChecksum>true</MSDeployUseChecksum>
</Project>
并选中在 Azure 发布管道中使应用程序脱机:部署 Azure 应用程序服务任务
我想制作 App_Offline.htm 自定义和可更新我正在使用 MSDeploy 以便从 Azure Pipeline 和 Visual Studio 2019 发布。Publish Works 支持两者。我的 Web 项目在 .Net Core 2.2
我的问题是我想使用 MSDeploy 使应用程序脱机,发布前和删除 app_offline.htm 发布后。目前,我启用 MSDeployAppOffline,它显示秒数的默认“维护中”。直到 App_offline.htm 在应用服务中上传。然后我使用 Kudu 在线删除它。
后来我决定使用 MSDeploy CMDLine 远程添加和删除文件 app_offline.htm、beforePublish 和 AfterPublish ... 这也有效,我必须在发布管道中以纯文本形式保存我的密码,并且在 Visual Studio 中,所有方式都是“批处理脚本、PowerShell 脚本 ...”。
我的发布资料
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<WebPublishMethod>MSDeploy</WebPublishMethod>
<PublishProvider>AzureWebSite</PublishProvider>
<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
<LastUsedPlatform>Any CPU</LastUsedPlatform>
<SiteUrlToLaunchAfterPublish>mySiteUrl</SiteUrlToLaunchAfterPublish>
<LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
<ExcludeApp_Data>False</ExcludeApp_Data>
<ProjectGuid>GUID</ProjectGuid>
<MSDeployServiceURL>myapp.scm.azurewebsites.net:443</MSDeployServiceURL>
<DeployIisAppPath>increditing-preview</DeployIisAppPath>
<RemoteSitePhysicalPath />
<SkipExtraFilesOnServer>True</SkipExtraFilesOnServer>
<MSDeployPublishMethod>WMSVC</MSDeployPublishMethod>
<EnableMSDeployBackup>True</EnableMSDeployBackup>
<UserName>$myapp</UserName>
<_SavePWD>True</_SavePWD>
<_DestinationType>AzureWebSite</_DestinationType>
<EnableMSDeployAppOffline>true</EnableMSDeployAppOffline>
<MSDeployUseChecksum>true</MSDeployUseChecksum>
<MSDeployPath Condition="'$(MSDeployPath)'==''">
$(Registry:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\IISExtensions\MSDeploy@InstallPath)</MSDeployPath>
<MSDeployExe Condition=" '$(MSDeployExe)'=='' ">$(MSDeployPath)msdeploy.exe</MSDeployExe>
<DeleteCMD>
"$(MSDeployExe)" -verb:delete -dest:contentPath="$(DeployIisAppPath)/App_offline.htm",ComputerName="https://$(DeployIisAppPath).scm.azurewebsites.net/msdeploy.axd?site=$(DeployIisAppPath)",UserName="$(UserName)",Password="Password",IncludeAcls='False',AuthType='Basic'
</DeleteCMD>
</PropertyGroup>
<Target Name="CustomActionsAfterPublish" AfterTargets="AfterPublish">
<PropertyGroup>
</PropertyGroup>
<Message Text="Inside AfterPublish" Importance="high" />
<!-- MSDeploy does not work -->
<!--<MSDeploy Verb="delete"
Source="@(MsDeploySourceProviderSetting)"
Destination="contentPath=myapp/App_Offline.htm,computername=$(MsDeployServiceUrl)"
AllowUntrusted="$(AllowUntrustedCertificate)"
UseChecksum="$(MSDeployUseChecksum)"
UserAgent="$(_MSDeployUserAgent)"
ExePath="$(MSDeployPath)" />-->
<!-- Executing this command I have to use my Password in Pain Text -->
<Exec Command="$(DeleteCMD)" ></Exec>
</Target>
</Project>
https://github.com/projectkudu/kudu/issues/2949
为了避免 Kudu 问题,我所要做的就是:
在我的 Azure 应用服务中添加应用程序设置
并将
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<WebPublishMethod>MSDeploy</WebPublishMethod>
<PublishProvider>AzureWebSite</PublishProvider>
<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
<LastUsedPlatform>Any CPU</LastUsedPlatform>
<SiteUrlToLaunchAfterPublish>mySiteUrl</SiteUrlToLaunchAfterPublish>
<LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
<ExcludeApp_Data>False</ExcludeApp_Data>
<ProjectGuid>GUID</ProjectGuid>
<MSDeployServiceURL>myapp.scm.azurewebsites.net:443</MSDeployServiceURL>
<DeployIisAppPath>increditing-preview</DeployIisAppPath>
<RemoteSitePhysicalPath />
<SkipExtraFilesOnServer>True</SkipExtraFilesOnServer>
<MSDeployPublishMethod>WMSVC</MSDeployPublishMethod>
<EnableMSDeployBackup>True</EnableMSDeployBackup>
<UserName>$myapp</UserName>
<_SavePWD>True</_SavePWD>
<_DestinationType>AzureWebSite</_DestinationType>
/// EnableMSDeployAppOffline
<EnableMSDeployAppOffline>true</EnableMSDeployAppOffline>
<MSDeployUseChecksum>true</MSDeployUseChecksum>
</Project>
并选中在 Azure 发布管道中使应用程序脱机:部署 Azure 应用程序服务任务