您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.

通过 Visual Studio 将 ASP.NET Web 应用发布到 Azure VMPublish an ASP.NET Web App to an Azure VM from Visual Studio

本文档介绍了如何发布到 Azure 虚拟机 (VM) 使用 ASP.NET web 应用程序Microsoft Azure 虚拟机在 Visual Studio 2019 发布功能。This document describes how to publish an ASP.NET web application to an Azure virtual machine (VM) using the Microsoft Azure Virtual Machines publishing feature in Visual Studio 2019.

必备组件Prerequisites

若要使用 Visual Studio 将 ASP.NET 项目发布到某个 Azure VM,必须正确设置该 VM。In order to use Visual Studio to publish an ASP.NET project to an Azure VM, the VM must be correctly set up.

使用 Visual Studio 将 ASP.NET Web 应用发布到 Azure VMPublish your ASP.NET web app to the Azure VM using Visual Studio

以下部分介绍如何将现有的 ASP.NET Web 应用程序发布到 Azure 虚拟机。The following section describes how to publish an existing ASP.NET web application to an Azure virtual machine.

  1. 在 Visual Studio 2019 中打开你的 web 应用解决方案。Open your web app solution in Visual Studio 2019.

  2. 在解决方案资源管理器中右键单击该项目,并选择“发布...”。 Right-click the project in Solution Explorer and choose Publish...

  3. 使用页面右侧的箭头滚动浏览发布选项,直到出现“Microsoft Azure 虚拟机”。 Use the arrow on the right of the page to scroll through the publishing options until you find Microsoft Azure Virtual Machines.

    发布页 - 右侧箭头

  4. 选择“Microsoft Azure 虚拟机”图标,然后选择“发布”。 Select the Microsoft Azure Virtual Machines icon and select Publish.

    发布页 -“Microsoft Azure 虚拟机”图标

  5. 选择相应的帐户(包含与虚拟机连接的 Azure 订阅)。Choose the appropriate account (with Azure subscription connected to your virtual machine).

    • 如果已登录 Visual Studio,则帐户列表中会填充所有已经过身份验证的帐户。If you're signed in to Visual Studio, the account list is populated with all your authenticated accounts.
    • 如果未登录,或者所需的帐户未列出,请选择“添加帐户...”并遵照提示登录。If you are not signed in, or if the account you need is not listed, choose "Add an account..." and follow the prompts to log in.
      Azure 帐户选择器
  6. 从“现有虚拟机”列表中选择相应的 VM。Select the appropriate VM from the list of Existing Virtual Machines.

    备注

    填充此列表可能需要一段时间。Populating this list can take some time.

    Azure VM 选择器

  7. 单击“确定”开始发布。Click OK to begin publishing.

  8. 当系统提示输入凭据,请提供用户名和密码的目标配置有发布权限的 VM 上的用户帐户。When prompted for credentials, supply the username and password of a user account on the target VM that is configured with publishing rights. 这些凭据通常是管理员用户名和密码创建 VM 时使用。These credentials are typically the admin username and password used when creating the VM.

    WebDeploy 登录

  9. 接受安全证书。Accept the security certificate.

    证书错误

  10. 观察“输出”窗口以检查发布操作的进度。Watch the Output window to check the progress of the publish operation.

    输出窗口

  11. 如果发布成功,则会启动浏览器并打开新发布的站点的 URL。If publishing is successful, a browser launches to open the URL of the newly published site.

成功!Success!

现已成功将 Web 应用发布到 Azure 虚拟机。You have now successfully published your web app to an Azure virtual machine.

发布页中的选项Publish Page Options

完成发布向导后,将在文档中打开“发布”页,其中已选中新的发布配置文件。After completing the publish wizard, the Publish page is opened in the document well with the new publishing profile selected.

重新发布Re-publish

若要将更新发布到 Web 应用程序,请在“发布”页上选择“发布”按钮。 To publish updates to your web application, select the Publish button on the Publish page.

  • 根据提示输入用户名和密码。If prompted, enter username and password.
  • 随即会开始发布。Publishing begins immediately.

发布页 -“发布”按钮

修改发布配置文件设置Modify publish profile settings

若要查看和修改发布配置文件设置,请选择“设置...”。 To view and modify the publish profile settings, select Settings....

发布页-“设置”按钮

设置应如下所示:Your settings should look something like this:

发布设置 -“连接”页

保存用户名和密码Save User name and Password

  • 避免每次发布时提供身份验证信息。Avoid providing authentication information every time you publish. 若要执行此操作,请填充用户名密码字段,然后选择保存密码框。To do so, populate the User name and Password fields, and select the Save password box.
  • 使用“验证连接”按钮确认是否输入了正确的信息。 Use the Validate Connection button to confirm that you have entered the right information.

部署到干净的 Web 服务器Deploy to clean web server

  • 如果你想要确保 web 服务器具有全新的 web 应用程序每次上传后,并且,没有其他文件保留在以前的部署,可以检查删除目标处的其他文件中的复选框设置选项卡。If you want to ensure that the web server has a clean copy of the web application after each upload and that no other files are left from a previous deployment, you can check the Remove additional files at destination checkbox in the Settings tab.

  • 警告:使用此设置进行发布删除 web 服务器 (包括 wwwroot 目录) 存在的所有文件。Warning: Publishing with this setting deletes all files that exist on the web server (wwwroot directory). 在启用此选项的情况下进行发布之前,请务必了解计算机的状态。Be sure you know the state of the machine before publishing with this option enabled.

发布设置 -“设置”页

后续步骤Next steps

设置 CI/CD 以自动部署到 Azure VMSet up CI/CD for automated deployment to Azure VM

若要使用 Azure Pipelines 设置持续交付管道,请参阅部署到 Windows 虚拟机To set up a continuous delivery pipeline with Azure Pipelines, see Deploy to a Windows Virtual Machine.