使用 Visual Studio 简化 Service Fabric 应用程序的编写和管理Use Visual Studio to simplify writing and managing your Service Fabric applications

可以通过 Visual Studio 管理 Azure Service Fabric 应用程序和服务。You can manage your Azure Service Fabric applications and services through Visual Studio. 设置开发环境之后,可以使用 Visual Studio 创建 Service Fabric 应用程序、添加服务,或在本地开发群集中打包、注册和部署应用程序。Once you've set up your development environment, you can use Visual Studio to create Service Fabric applications, add services, or package, register, and deploy applications in your local development cluster.

部署 Service Fabric 应用程序Deploy your Service Fabric application

默认情况下,部署一个应用程序会将以下步骤合并为一个简单的操作:By default, deploying an application combines the following steps into one simple operation:

  1. 创建应用程序包Creating the application package
  2. 将应用程序包上传到映像存储Uploading the application package to the image store
  3. 注册应用程序类型Registering the application type
  4. 删除任何正在运行的应用程序实例Removing any running application instances
  5. 删除应用程序实例Creating an application instance

在 Visual Studio 中,按 F5 部署应用程序,然后将调试程序附加到所有应用程序实例。In Visual Studio, pressing F5 deploys your application and attach the debugger to all application instances. 可以按 Ctrl+F5 部署应用程序而不进行调试,也可以使用发布配置文件将应用程序发布到本地或远程群集。You can use Ctrl+F5 to deploy an application without debugging, or you can publish to a local or remote cluster by using the publish profile.

应用程序调试模式Application Debug Mode

Visual Studio 提供一个名为“应用程序调试模式” 的属性,它控制 Visual Studio 在调试时如何处理应用程序部署。Visual Studio provide a property called Application Debug Mode, which controls how you want Visual Studios to handle Application deployment as part of debugging.

设置“应用程序调试模式”属性To set the Application Debug Mode property

  1. 在 Service Fabric 应用程序项目 (*.sfproj) 的快捷菜单上,选择“属性” (或按 F4 键)。On the Service Fabric application project's (*.sfproj) shortcut menu, choose Properties (or press the F4 key).

  2. 在“属性”窗口中,设置“应用程序调试模式”属性。In the Properties window, set the Application Debug Mode property.

    设置“应用程序调试模式”属性

应用程序调试模式Application Debug Modes

  1. 刷新应用程序 此模式能快速更改和调试代码并支持调试时编辑静态 Web 文件。Refresh Application This mode enables you to quickly change and debug your code and supports editing static web files while debugging. 此模式只有在本地开发群集处于 1 节点模式下时有效。This mode only works if your local development cluster is in 1-Node mode. 这是默认的应用程序调试模式。This is the default Application Debug Mode.
  2. 删除应用程序:在调试会话结束后,删除应用程序。Remove Application causes the application to be removed when the debug session ends.
  3. 自动升级 调试会话结束时,应用程序继续运行。Auto Upgrade The application continues to run when the debug session ends. 下一个调试会话将部署视为升级。The next debug session will treat the deployment as an upgrade. 此升级过程会暂留用户在上一个调试会话中输入的所有数据。The upgrade process preserves any data that you entered in a previous debug session.
  4. 保留应用程序 调试会话结束时,应用程序在群集中继续运行。Keep Application The application keeps running in the cluster when the debug session ends. 在下一个调试会话开始时将删除应用程序。At the beginning of the next debug session, the application will be removed.

对于自动升级 ,数据是通过应用 Service Fabric 的应用程序升级功能予以保留。For Auto Upgrade data is preserved by applying the application upgrade capabilities of Service Fabric. 若要详细了解如何升级应用程序,以及如何在真实环境中执行升级,请参阅 Service Fabric 应用程序升级For more information about upgrading applications and how you might perform an upgrade in a real environment, see Service Fabric application upgrade.

向 Service Fabric 应用程序添加服务Add a service to your Service Fabric application

可以向应用程序中添加新的服务来扩展其功能。You can add new services to your application to extend its functionality. 为了确保应用程序包中包含服务,请通过“新建 Fabric 服务... ”菜单项添加服务。To ensure that the service is included in your application package, add the service through the New Fabric Service... menu item.

添加新的 Service Fabric 服务

选择要添加到应用程序的 Service Fabric 项目类型,并指定服务的名称。Select a Service Fabric project type to add to your application, and specify a name for the service. 请参阅为服务选择框架,这篇文章有助于确定要使用的服务类型。See Choosing a framework for your service to help you decide which service type to use.

选择要添加到应用程序的 Service Fabric 服务项目类型

新的服务会添加到解决方案和现有的应用程序包中。The new service is added to your solution and existing application package. 服务引用和默认服务实例将添加到应用程序清单中,导致服务创建并在下次部署应用程序时启动。The service references and a default service instance will be added to the application manifest, causing the service to be created and started the next time you deploy the application.

新的服务会添加到应用程序清单中

打包 Service Fabric 应用程序Package your Service Fabric application

要将应用程序及其服务部署到群集中,需要创建应用程序包。To deploy the application and its services to a cluster, you need to create an application package. 该包整理应用程序清单、服务清单和特定布局的其他必要文件。The package organizes the application manifest, service manifests, and other necessary files in a specific layout. Visual Studio 设置和管理“pkg”目录中应用程序项目的文件夹中的包。Visual Studio sets up and manages the package in the application project's folder, in the 'pkg' directory. 单击“应用程序”上下文菜单中的“”可创建或更新应用程序包。Clicking Package from the Application context menu creates or updates the application package.

使用云资源管理器删除应用程序和应用程序类型Remove applications and application types using Cloud Explorer

可以在 Visual Studio 中使用 Cloud Explorer(可通过“视图”菜单启动)执行基本的群集管理操作。You can perform basic cluster management operations from within Visual Studio using Cloud Explorer, which you can launch from the View menu. 例如,可以删除本地或远程群集上的应用程序和取消设置其上的应用程序类型。For instance, you can delete applications and unprovision application types on local or remote clusters.

删除应用程序

Tip

有关更丰富的群集管理功能,请参阅使用 Service Fabric Explorer 可视化群集For a richer cluster management functionality, see Visualizing your cluster with Service Fabric Explorer.

后续步骤Next steps