将应用部署到文件夹、IIS、Azure 或其他目标Deploy your app to a folder, IIS, Azure, or another destination

通过部署应用程序、服务或组件,你可以将其分发以便安装于其他计算机、设备、服务器或云中。By deploying an application, service, or component, you distribute it for installation on other computers, devices, servers, or in the cloud. 你需要在 Visual Studio 中为所需的部署类型选择适当的方法。You choose the appropriate method in Visual Studio for the type of deployment that you need.

获取有关部署任务的帮助:Get help for your deployment task:

哪些发布选项适合我?What publishing options are right for me?

在 Visual Studio 中,应用程序可以直接发布到以下目标:From within Visual Studio, applications can be published directly to the following targets:

创建新的发布配置文件时,将显示上述选项,如下图所示。The preceding options appear as shown in the following illustration when you create a new publish profile.

选择发布选项

选择发布选项

若要快速浏览更常见的应用程序部署选项,请参阅初探部署For a quick tour of more general application deployment options, see First look at deployment.

AzureAzure

当你选择 Azure 时,可以在以下选项中进行选择:When you choose Azure, you can choose between:

选择一项 Azure 服务

Azure 应用服务Azure App Service

Azure 应用服务帮助开发人员快速创建可缩放的 Web 应用程序和服务,而无需维护基础结构。Azure App Service helps developers quickly create scalable web applications and services without maintaining infrastructure. 应用服务在 Azure 的云托管虚拟机上运行,但这些虚拟机是为你而托管的。An App Service runs on cloud-hosted virtual machines in Azure, but those virtual machines are managed for you. 应用服务中的每个应用均分配有一个唯一的 *.azurewebsites.net URL;除免费层以外的所有定价层允许向站点分配自定义域名。Each app in an App Service will be assigned a unique *.azurewebsites.net URL; all pricing tiers other than Free allow assigning custom domain names to the site.

用户可通过为包含的应用服务选择定价层或计划来确定应用服务具有的计算能力。You determine how much computing power an App Service has by choosing a pricing tier or plan for the containing App Service. 而且不必更改定价层就能让多个 Web 应用(和其他应用类型)共享同一个应用服务。You can have multiple Web apps (and other app types) share the same App Service without changing the pricing tier. 例如,可以在同一个应用服务上同时托管开发、过渡和生产 Web 应用。For example, you can host development, staging, and production Web apps together on the same App Service.

何时选用 Azure 应用服务When to choose Azure App Service

  • 希望部署可通过 Internet 访问的 Web 应用程序。You want to deploy a web application that's accessible through the Internet.
  • 希望根据需求自动缩放 Web 应用程序,而无需重新部署。You want to automatically scale your web application according to demand without needing to redeploy.
  • 无需维护服务器基础结构(包括软件更新)。You don't want to maintain server infrastructure (including software updates).
  • 不需要在托管 Web 应用程序的服务器上进行任何计算机级别的自定义设置。You don't need any machine-level customizations on the servers that host your web application.

如果想在自己的数据中心或其他本地计算机中使用 Azure 应用服务,可以使用 Azure 堆栈来实现。If you want to use Azure App Service in your own datacenter or other on-premises computers, you can do so using the Azure Stack.

有关发布到应用服务的详细信息,请参阅以下链接:For more information on publishing to App Service, see:

Azure 容器注册表Azure Container Registry

使用 Azure 容器注册表,可以在专用注册表中为所有类型的容器部署生成、存储和管理 Docker 容器映像与项目。Azure Container Registry allows you to build, store, and manage Docker container images and artifacts in a private registry for all types of container deployments.

何时选择 Azure 容器注册表When to choose Azure Container Registry

  • 有现成的 Docker 容器开发和部署管道。When you have an existing Docker container development and deployment pipeline.
  • 要在 Azure 中生成 Docker 容器映像。When you want to build Docker container images in Azure.

更多相关信息:For more information:

Azure 虚拟机Azure Virtual Machine

Azure 虚拟机 (VM) 可用于在云中创建和管理任意数量的计算资源。Azure Virtual Machines (VMs) lets you create and manage any number of computing resources in the cloud. 通过负责 VM 上的所有软件和更新,你可以根据应用程序的需求尽可能地对这些 VM 进行自定义。By assuming responsibility for all software and updates on the VMs, you can customize them as much as desired as required by your application. 此外,可以通过远程桌面直接访问虚拟机,只要需要,各服务器就会一直维持分配给它的 IP 地址。You can access the virtual machines directly through Remote Desktop, and each one will maintain its assigned IP address as long as desired.

缩放虚拟机上托管的应用程序时,需要根据需求起转额外的 VM,然后部署必要的软件。Scaling an application that's hosted on virtual machines involves spinning up additional VMs according to demand and then deploying the necessary software. 利用这种额外的控制能力,可以在全球不同区域以不同方式进行缩放。This additional level of control lets you scale differently in different global regions. 例如,如果应用程序要为多个地区办事处的员工提供服务,则可以根据这些地区的员工人数来缩放 VM,从而潜在地降低成本。For example, if your application is serving employees in a variety of regional offices, you can scale your VMs according to the number of employees in those regions, potentially reducing costs.

有关更多信息,请参阅 Azure 应用服务、Azure 虚拟机以及可通过 Visual Studio 中的“自定义”选项设置为部署目标的其他 Azure 服务之间的详细比较For additional information, see the detailed comparison between Azure App Service, Azure Virtual Machines, and other Azure services that you can use as a deployment target using the Custom option in Visual Studio.

何时选择 Azure 虚拟机When to choose Azure Virtual Machines

  • 希望部署可通过 Internet 访问的 Web 应用程序,并能完全控制所分配 IP 地址的生存期。You want to deploy a web application that's accessible through the Internet, with full control over the lifetime of assigned IP addresses.
  • 需要在服务器上进行计算机级别的自定义设置,其中包括诸如专用数据库系统、特定网络配置、磁盘分区之类的附加软件。You need machine-level customizations on your servers, which include additional software such as a specialized database system, specific networking configurations, disk partitions, and so forth.
  • 希望精细地控制 Web 应用程序的缩放。You want a fine level of control over scaling of your web application.
  • 出于任何其他原因,需要直接访问托管应用程序的服务器。You need direct access to the servers hosting your application for any other reason.

如果想在自己的数据中心或其他本地计算机中使用 Azure 虚拟机,可以使用 Azure 堆栈来实现。If you want to use Azure Virtual Machines in your own datacenter or other on-premises computers, you can do so using the Azure Stack.

Docker 容器注册表Docker container registry

如果你的应用程序使用 Docker,则可以将容器化应用程序发布到 Docker 容器注册表。If your application is using Docker, you can publish your containerized application to a Docker container registry.

何时选择 Docker 容器注册表When to choose Docker Container Registry

  • 需要部署容器化应用程序You want to deploy a containerized application

有关详细信息,请参阅以下部分:For more information, see the following:

文件夹Folder

部署到文件系统意味着将应用程序文件复制到你自己的计算机上的特定文件夹中。Deploying to the file system means to copy your application's files to a specific folder on your own computer. 部署到文件夹最常用于测试目的,如果计算机还运行服务器,则可以通过这种方式将应用程序部署为供数量有限的人员使用。Deploying to a folder is most often used for testing purposes, or to deploy the application for use by a limited number of people if the computer is also running a server. 如果目标文件夹在网络上共享,那么,通过部署到文件系统能够使 Web 应用程序文件可供其他人访问,这些人随后可将其部署到特定服务器。If the target folder is shared on a network, then deploying to the file system can make the web application files available to others who might then deploy it to specific servers.

从 Visual Studio 2019 16.8 开始,文件夹目标包括使用 ClickOnce 发布 .Net Windows 应用程序的功能。Starting with Visual Studio 2019 16.8, the folder target includes the ability to publish a .Net Windows application using ClickOnce.

如果你希望使用 ClickOnce 发布 .NET Core 3.1 或更高版本的 Windows 应用程序,请参阅使用 ClickOnce 部署 .NET Windows 应用程序If you wish to publish a .NET Core 3.1, or newer, Windows application with ClickOnce, see Deploy a .NET Windows application using ClickOnce.

任何运行服务器的本地计算机都可以使应用程序能够通过 Internet 或 Intranet(取决于其配置方式和所连接的网络)访问。Any local machines that are running a server can make your application available through the Internet or an Intranet depending on how it's configured and the networks to which it's connected. (如果将计算机直接连接到 Internet,应特别小心,以免其受到外部安全威胁。)这些计算机由你管理,因此你可以完全控制软件和硬件配置。(If you do connect a computer directly to the Internet, be especially careful to protect it from external security threats.) Because you manage these machines, you're in complete control of the software and hardware configurations.

如果出于任何原因(如计算机访问权限)不能使用云服务,例如 Azure 应用服务或 Azure 虚拟机,可以在自己的数据中心使用 Azure StackIf for any reason (such as machine access) you are not able to use cloud services like Azure App Service or Azure Virtual Machines, you can use the Azure Stack in your own datacenter. Azure 堆栈可用于通过 Azure 应用服务和 Azure 虚拟机来管理并使用计算资源,并且让所有资源仍然保留在本地。The Azure Stack allows you to manage and use computing resources through Azure App Service and Azure Virtual Machines while yet keeping everything on-premises.

何时选用文件系统部署When to choose file system deployment

  • 仅需要将应用程序部署到文件共享,其他人可从中将其部署到不同的服务器。You need only deploy the application to a file share from which others will deploy it to different servers.
  • 使用 ClickOnce 部署 .NET Windows 应用程序You want to deploy a .NET Windows Application using ClickOnce
  • 仅需要本地测试部署。You need only a local test deployment.
  • 在将应用程序文件发送到另一个部署目标之前,想单独对文件进行检查并在必要时进行修改。You want to examine and potentially modify the application files independently before sending them onto another deployment target.

有关详细信息,请参阅快速入门 - 部署到本地文件夹For more information, see Quickstart - Deploy to a local folder.

有关使用 ClickOnce 部署 .NET Windows 应用程序的详细信息,请参阅使用 ClickOnce 部署 .NET Windows 应用程序For more information on deploying a .NET Windows Application using ClickOnce, see Deploy a .NET Windows application using ClickOnce.

有关选择设置的更多帮助,请参阅以下内容:For additional help to choose your settings, see the following:

FTP/FTPS 服务器FTP/FTPS server

使用 FTP/FTPS 服务器可以将应用程序部署到 Azure 以外的服务器。An FTP/FTPS server lets you deploy your application to a server other than Azure. 它可以部署到你有权访问的文件系统或任何其他服务器(Internet 或 Intranet),包括其他云服务上的服务器。It can deploy to a file system or any other server (Internet or Intranet) to which you have access, including those on other cloud services. 它可以与 Web 部署(文件或 .ZIP)和 FTP 配合使用。It can work with web deploy (files or .ZIP) and FTP.

如果选择 FTP/FTPS 服务器,Visual Studio 会提示输入配置文件名称,然后收集包括目标服务器或位置、站点名称和凭据在内的其他连接信息。When choosing a FTP/FTPS server, Visual Studio prompts you for a profile name, and then collects additional Connection information including the target server or location, a site name, and credentials. 可以在“设置”选项卡上控制以下行为:You can control the following behaviors on the Settings tab:

  • 要部署的配置。The configuration you want to deploy.
  • 是否从目标中删除现有文件。Whether to remove existing files from the destination.
  • 是否在发布期间预编译。Whether to precompile during publishing.
  • 是否要从部署中排除 App_Data 文件夹中的文件。Whether to exclude files in the App_Data folder from deployment.

可以在 Visual Studio 中创建任意数量的 FTP/FTPS 部署配置文件,从而管理设置不同的配置文件。You can create any number of FTP/FTPS deployment profiles in Visual Studio, making it possible to manage profiles with different settings.

何时选择 FTP/FTPS 服务器部署When to choose FTP/FTPS server deployment

  • 在除 Azure 以外的可通过 URL 访问的提供程序上使用云服务。You're using cloud services on a provider other than Azure that can be accessed through URLs.
  • 希望用来进行部署的凭据不是在 Visual Studio 中所用的凭据或直接与 Azure 帐户相关联的凭据。You want to deploy using credentials other than the ones that you use within Visual Studio, or those tied directly to your Azure accounts.
  • 希望在每次部署时从目标中删除文件。You want to delete files from the target each time you deploy.

Web 服务器 (IIS)Web Server (IIS)

使用 IIS Web 服务器可以将应用程序部署到 Azure 以外的其他 Web 服务器。An IIS web server lets you deploy your application to a web server other than Azure. 它可以部署到你有权访问的 IIS 服务器(Internet 或 Intranet),包括其他云服务上的服务器。It can deploy to an IIS server (Internet or Intranet) to which you have access, including those on other cloud services. 它可以与 Web 部署或 Web 部署包一起使用。It can work with Web Deploy or a Web Deploy package.

如果选择 IIS Web 服务器,Visual Studio 会提示输入配置文件名称,然后收集包括目标服务器或位置、站点名称和凭据在内的其他连接信息。When choosing an IIS web server, Visual Studio prompts you for a profile name, and then collects additional Connection information including the target server or location, a site name, and credentials. 可以在“设置”选项卡上控制以下行为:You can control the following behaviors on the Settings tab:

  • 要部署的配置。The configuration you want to deploy.
  • 是否从目标中删除现有文件。Whether to remove existing files from the destination.
  • 是否在发布期间预编译。Whether to precompile during publishing.
  • 是否要从部署中排除 App_Data 文件夹中的文件。Whether to exclude files in the App_Data folder from deployment.

可以在 Visual Studio 中创建任意数量的 IIS Web 服务器部署配置文件,从而管理设置不同的配置文件。You can create any number of IIS web server deployment profiles in Visual Studio, making it possible to manage profiles with different settings.

何时选择 Web 服务器 (IIS) 部署When to choose web server (IIS) deployment

  • 要使用 IIS 发布可通过 URL 访问的站点或服务。You're using IIS to publish a site or service that can be accessed through URLs.
  • 希望用来进行部署的凭据不是在 Visual Studio 中所用的凭据或直接与 Azure 帐户相关联的凭据。You want to deploy using credentials other than the ones that you use within Visual Studio, or those tied directly to your Azure accounts.
  • 希望在每次部署时从目标中删除文件。You want to delete files from the target each time you deploy.

有关详细信息,请参阅快速入门 - 部署到网站For more information, see Quickstart - Deploy to a web site.

有关排查 IIS 上的 ASP.NET Core 故障的帮助信息,请参阅排查 Azure 应用服务和 IIS 上的 ASP.NET Core 故障For help with troubleshooting ASP.NET Core on IIS, see Troubleshoot ASP.NET Core on Azure App Service and IIS.

导入配置文件Import Profile

在发布到 IIS 或 Azure 应用服务时,可以导入配置文件。You can import a profile when publishing to IIS or Azure App Service. 可以使用发布设置文件 (*.publishsettings) 配置部署。You can configure deployment using a publish settings file (*.publishsettings). 发布设置文件由 IIS 或 Azure 应用服务创建,或者可手动创建,然后可将其导入 Visual Studio。A publish settings file is created by IIS or Azure App Service, or it can be manually created, and then it can be imported into Visual Studio.

使用发布设置文件可以简化部署配置,与手动配置每个部署配置文件相比,在团队环境中效果更好。Use of a publish settings file can simplify deployment configuration and works better in a team environment versus manually configuring each deployment profile.

何时选择导入配置文件When to choose import profile

  • 要发布到 IIS 并且要简化部署配置时。You're publishing to IIS and want to simplify deployment configuration.
  • 要发布到 IIS 或 Azure 应用服务,并且需要加快部署配置速度,以便重用或让团队成员发布到同一服务时。You're publishing to IIS or Azure App Service and want to speed up deployment configuration for reuse or for team members publishing to the same service.

有关详细信息,请参阅以下主题:For more information, see the following:

配置 .NET 部署设置Configure .NET deployment settings

有关选择设置的更多帮助,请参阅以下内容:For additional help to choose your settings, see the following:

后续步骤Next steps

教程:Tutorials: