azure - 使用 MSDeploy 将 Web 应用程序部署到 Azure 应用服务

标签 azure azure-web-app-service msdeploy

我在使用 MSDeploy 将 Web 应用程序部署到 Azure 应用服务时遇到很多麻烦。我需要使用哪些命令行参数?

最佳答案

MSDeploy 接受参数的方式有点挑剔。首先,该命令需要您的应用服务的用户名和密码。这可以通过在 PowerShell 中使用 Azure CLI 找到,如下所示:

$publishProfile = az webapp deployment list-publishing-profiles --resource-group <ResourceGroupName> --name <WebAppName> --query "[?publishMethod=='MSDeploy']" | ConvertFrom-Json

这会将用户名和密码放入 $publishProfile 变量中,以便稍后与 MSDeploy 一起使用。

接下来,如果源发布网站的路径中包含空格并且正在使用 PowerShell,则需要将其转换为等效的短名称语法。如果不这样做,MSDeploy 将抛出无意义的异常,如下所示,这些异常很难诊断。

Error Code: ERROR_PROVIDER_NOT_FOUND More Information: The provider 'dirPath=' could not be found. Learn more at: https://go.microsoft.com/fwlink/?LinkId=221672#ERROR_PROVIDER_NOT_FOUND. at Microsoft.Web.Deployment.DeploymentProviderSettingCollection..ctor(String factoryName) at Microsoft.Web.Deployment.DeploymentProviderOptions..ctor(String factoryName) at MSDeploy.MSDeploy.GetObjectParameters(Dictionary`2 parameters, Boolean isDestination, DeploymentBaseOptions& retbaseOptions, DeploymentProviderOptions& retproviderOptions) at MSDeploy.MSDeploy.ExecuteWorker() at MSDeploy.MSDeploy.Execute() at MSDeploy.MSDeploy.Main(String[] unusedArgs) Error count: 1.

要将路径转换为其等效的短名称,请使用以下命令:

$shortPath = (New-Object -ComObject Scripting.FileSystemObject).GetFolder(".\Publish").ShortPath

最后,这是运行 MSDeploy 并将 Web 应用程序部署到 Azure 的命令。为了使用下面的命令,需要定义 $webAppName 变量。

$webAppName = "MyWebApp"
&"C:\Program Files\IIS\Microsoft Web Deploy V3\msdeploy.exe" -verb:sync -source:dirPath="$shortPath",includeAcls=false -dest:dirpath=D:\home\site\wwwroot,ComputerName="https://$webAppName.scm.azurewebsites.net/msdeploy.axd?site=$($webAppName)",UserName=$($publishProfile.userName),Password=$($publishProfile.userPWD),AuthType='Basic' -verbose -debug

该命令应返回类似于以下内容的输出:

Info: Using ID 'd5e5eb3d-...' for connections to the remote server.
Verbose: Pre-authenticating to remote agent URL 'https://webappname.scm.azurewebsites.net/msdeploy.axd?site=webappname' as '$webappname'.
Verbose: Performing synchronization pass #1.
Verbose: Pre-authenticating to remote agent URL 'https://webappname.scm.azurewebsites.net/msdeploy.axd?site=webappname' as '$webappname'.
Verbose: Received response from agent (HTTP status 'OK').
Info: Adding directory (D:\home\site\wwwroot\cs).
Info: Adding directory (D:\home\site\wwwroot\de).
Info: Adding directory (D:\home\site\wwwroot\es).
Info: Adding directory (D:\home\site\wwwroot\fr).
Info: Deleting file (D:\home\site\wwwroot\hostingstart.html).
Info: Adding directory (D:\home\site\wwwroot\it).
Info: Adding directory (D:\home\site\wwwroot\ja).
Info: Adding directory (D:\home\site\wwwroot\ko).
Info: Adding directory (D:\home\site\wwwroot\pl).
Info: Adding directory (D:\home\site\wwwroot\pt-BR).
Info: Adding directory (D:\home\site\wwwroot\ru).
Info: Adding directory (D:\home\site\wwwroot\runtimes).
Info: Adding directory (D:\home\site\wwwroot\runtimes\unix).
Info: Adding directory (D:\home\site\wwwroot\runtimes\unix\lib).
Info: Adding directory (D:\home\site\wwwroot\runtimes\unix\lib\netcoreapp2.0).
Info: Adding directory (D:\home\site\wwwroot\runtimes\unix\lib\netcoreapp2.1).
Info: Adding directory (D:\home\site\wwwroot\runtimes\win).
Info: Adding directory (D:\home\site\wwwroot\runtimes\win\lib).
Info: Adding directory (D:\home\site\wwwroot\runtimes\win\lib\netcoreapp2.0).
Info: Adding directory (D:\home\site\wwwroot\runtimes\win\lib\netcoreapp2.1).
Info: Adding directory (D:\home\site\wwwroot\runtimes\win\lib\netstandard2.0).
Info: Adding directory (D:\home\site\wwwroot\runtimes\win-arm64).
Info: Adding directory (D:\home\site\wwwroot\runtimes\win-arm64\native).
Info: Adding directory (D:\home\site\wwwroot\runtimes\win-x64).
Info: Adding directory (D:\home\site\wwwroot\runtimes\win-x64\native).
Info: Adding directory (D:\home\site\wwwroot\runtimes\win-x86).
Info: Adding directory (D:\home\site\wwwroot\runtimes\win-x86\native).
Info: Adding directory (D:\home\site\wwwroot\tr).
Info: Adding directory (D:\home\site\wwwroot\zh-Hans).
Info: Adding directory (D:\home\site\wwwroot\zh-Hant).
Verbose: The dependency check 'DependencyCheckInUse' found no issues.
Verbose: The current synchronization pass is missing stream content for 201 objects.
Info: Using ID '1f1ab053-88c6-40a2-90e4-5347157542e6' for connections to the remote server.
Verbose: Performing synchronization pass #2.
Verbose: Pre-authenticating to remote agent URL 'https://webappname.scm.azurewebsites.net/msdeploy.axd?site=webappname' as '$webappname'.
...
Verbose: The HTTP connection (ID='1f1ab053-88c6-40a2-90e4-5347157542e6', type ='GetTraceStatus') is being kept alive while the request is processed.
Verbose: Received response from agent (HTTP status 'OK').
...
Verbose: The dependency check 'DependencyCheckInUse' found no issues.
Verbose: The synchronization completed in 2 pass(es).
Total changes: 231 (230 added, 1 deleted, 0 updated, 0 parameters changed, 44498979 bytes copied)

关于azure - 使用 MSDeploy 将 Web 应用程序部署到 Azure 应用服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63980135/

相关文章:

amazon-web-services - 在 Azure 应用服务和 AWS ECS 服务之间建立私有(private)安全连接的最佳方法

c# - 我首先使用实体​​框架数据库,我想将连接字符串存储在 Key Vault 中,并且需要使用 C# 代码中的应用程序设置从代码进行访问?

node.js - 在azure中配置node js时有没有办法指示架构(32位或64位)?

c# - Azure Web App 部署 msdeploy 包时出现错误

asp.net - 获取 ASP.NET 中 Azure AD 应用程序注册的所有 appRoles

c# - 发布到 Azure 后 Global.asax 中出现解析错误

azure - 您可以在不部署整个网站的情况下替换 Azure 网站中的选定文件吗?

visual-studio-2012 - 使用MS Build的IIS WebDeploy失败,错误为MSB4044 -ConcatFullServiceUrlWithSiteName任务

asp.net-mvc - 如何在发布过程中跳过文件夹删除?

.net - 防止未处理的异常破坏 Azure 辅助角色