在Azure App Service和Visual Studio中脱机自动化应用程序 [英] Automatize App Offline in Azure App Service and Visual Studio

本文介绍了在Azure App Service和Visual Studio中脱机自动化应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使App_Offline.htm自定义和可更新我正在使用MSDeploy以便从Azure Pipeline和Visual Studio 2019中发布.在这两者中发布Works fins.我的Web项目在.Net Core 2.2上

我的问题是我想使用MSDeploy将应用程序脱机,在发布之前并删除app_offline.htm在发布后.目前,我EnableMSDeployAppOffline,它显示默认的维护中"秒数.直到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>发布</LastUsedBuildConfiguration>< LastUsedPlatform>任何CPU</LastUsedPlatform>< SiteUrlToLaunchAfterPublish> mySiteUrl</SiteUrlToLaunchAfterPublish>< LaunchSiteAfterPublish> True</LaunchSiteAfterPublish>< ExcludeApp_Data>否</ExcludeApp_Data>< ProjectGuid> GUID</ProjectGuid>< MSDeployServiceURL> myapp.scm.azurewebsites.net:443</MSDeployServiceURL>< DeployIisAppPath> increditing-preview</DeployIisAppPath>< RemoteSitePhysicalPath/>< SkipExtraFilesOnServer>真实</SkipExtraFilesOnServer>< MSDeployPublishMethod> WMSVC</MSDeployPublishMethod>< EnableMSDeployBackup> True</EnableMSDeployBackup>< UserName> $ myapp</UserName>< _SavePWD>真</_ SavePWD>< _DestinationType> AzureWebSite</_ DestinationType>< EnableMSDeployAppOffline> true</EnableMSDeployAppOffline>< MSDeployUseChecksum> true</MSDeployUseChecksum>< MSDeployPath Condition ='$(MSDeployPath)'==''">$(注册表:HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ IISExtensions \ MSDeploy \ 3 @ InstallPath)</MSDeployPath>< MSDeployExe Condition ='$(MSDeployExe)'==''"> $(MSDeployPath)msdeploy.exe</MSDeployExe>< DeleteCMD>"$(MSDeployExe)" -verb:删除-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><目标名称="CustomActionsAfterPublish" AfterTargets ="AfterPublish">< PropertyGroup></PropertyGroup>< Message Text ="Inside AfterPublish" Importance ="high"/><!-MSDeploy不起作用-><!-< MSDeploy Verb ="delete"Source ="@(MsDeploySourceProviderSetting)"Destination ="contentPath = myapp/App_Offline.htm,computername = $(MsDeployServiceUrl)"AllowUntrusted ="$(AllowUntrustedCertificate)"UseChecksum ="$(MSDeployUseChecksum)"UserAgent ="$(_ MSDeployUserAgent)"ExePath ="$(MSDeployPath)"/>-><!-执行此命令,我必须在疼痛文本"中使用我的密码->< Exec Command ="$(DeleteCMD)"></Exec></Target></Project> 

解决方案

并添加<对我的发布配置文件EnableMSDeployAppOffline> true.

 < Project ToolsVersion ="4.0" xmlns ="http://schemas.microsoft.com/developer/msbuild/2003">< PropertyGroup>< WebPublishMethod> MSDeploy</WebPublishMethod>< PublishProvider> AzureWebSite</PublishProvider>< LastUsedBuildConfiguration>发布</LastUsedBuildConfiguration>< LastUsedPlatform>任何CPU</LastUsedPlatform>< SiteUrlToLaunchAfterPublish> mySiteUrl</SiteUrlToLaunchAfterPublish>< LaunchSiteAfterPublish> True</LaunchSiteAfterPublish>< ExcludeApp_Data>否</ExcludeApp_Data>< ProjectGuid> GUID</ProjectGuid>< MSDeployServiceURL> myapp.scm.azurewebsites.net:443</MSDeployServiceURL>< DeployIisAppPath> increditing-preview</DeployIisAppPath>< RemoteSitePhysicalPath/>< SkipExtraFilesOnServer>真实</SkipExtraFilesOnServer>< MSDeployPublishMethod> WMSVC</MSDeployPublishMethod>< EnableMSDeployBackup> True</EnableMSDeployBackup>< UserName> $ myapp</UserName>< _SavePWD>真</_ SavePWD>< _DestinationType> AzureWebSite</_ DestinationType>///EnableMSDeployAppOffline< EnableMSDeployAppOffline> true</EnableMSDeployAppOffline>< MSDeployUseChecksum> true</MSDeployUseChecksum></Project> 

并选中在Azure发布管道中使应用程序脱机:部署Azure应用程序服务任务

I want to Make App_Offline.htm Custom and updatable I'm using MSDeploy in order to publish from both Azure Pipeline and Visual Studio 2019. Publish Works fins in Both. My Web Project is on .Net Core 2.2

My problem is that I want to Take The App Offline, BeforePublish and Delete app_offline.htm AfterPublish, Using MSDeploy. For the moment, I EnableMSDeployAppOffline , which shows the default "Under Maintenance" for Seconds. Until App_offline.htm is uploaded in the app service. And then I delete it using Kudu online.

Later I decided to use MSDeploy CMDLine to remotely add and delete file app_offline.htm, beforePublish , and AfterPublish ... Wich Works also, I have to save my password in plain text in the release pipeline, and in Visual Studio, in all way "Batch Script, PowerShell Script ...".

My Publish Profile

<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\3@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

All I have to do in order to avoid Kudu issue is :

Add an Application setting in my Azure App Service

and add < EnableMSDeployAppOffline >true to my publish profile .

    <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>

And check Take App Offline in Azure Release Pipeline: Deploy Azure App Service Task

这篇关于在Azure App Service和Visual Studio中脱机自动化应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆