使用 Visual Studio 创建 .NET Core 应用程序并将其发布到远程 Linux Service Fabric 群集Use Visual Studio to create and publish .NET Core applications targeting a remote Linux Service Fabric cluster

可以使用 Visual Studio 工具开发 .NET Core 应用程序并将其发布到 Linux Service Fabric 群集。With Visual Studio tooling you can develop and publish Service Fabric .NET Core applications targeting a Linux Service Fabric cluster. SDK 版本必须为 3.4 或更高才能在 Visual Studio 中将 .NET Core 应用程序部署到 Linux Service Fabric 群集。The SDK version must be 3.4 or above to deploy a .NET Core application targeting Linux Service Fabric clusters from Visual Studio.

备注

Visual Studio 不支持调试面向 Linux 的 Service Fabric 应用程序。Visual Studio doesn't support debugging Service Fabric applications which target Linux.

创建面向 .NET Core 的 Service Fabric 应用程序Create a Service Fabric application targeting .NET Core

  1. 以管理员身份启动 Visual Studio。 Launch Visual Studio as an administrator.

  2. 通过单击“文件”->“新建”->“项目”来创建项目。 Create a project with File->New->Project.

  3. 在“新建项目”对话框中,选择“云”->“Service Fabric 应用程序”。 In the New Project dialog, choose Cloud -> Service Fabric Application.

    create-application

  4. 命名应用程序,并单击“确定” 。Name the application and click Ok.

  5. 在“新建 Service Fabric 服务”页中,选择要在“.NET Core 部分”创建的服务类型。 On the New Service Fabric Service page, select the type of service you would like to create under the .Net Core Section.

    create-service

部署到远程 Linux 群集Deploy to a remote Linux cluster

  1. 在“解决方案资源管理器”中,右键单击该应用程序并选择“生成”。 In the solution explorer, right click on the application and select Build.

    build-application

  2. 应用程序的生成过程完成后,右键单击服务,然后选择编辑 csproj 文件Once the build process for the application has completed, right click on the service and select edit the csproj file.

    edit-csproj

  3. 将 UpdateServiceFabricManifestEnabled 属性从 True 编辑为 False,前提是服务为执行组件项目类型Edit the UpdateServiceFabricManifestEnabled property from True to False if the service is an actor project type. 如果应用程序没有执行组件服务,请跳到步骤 4。If your application does not have an actor service, skip to step 4.

    <UpdateServiceFabricManifestEnabled>False</UpdateServiceFabricManifestEnabled>
    

    备注

    将 UpdateServiceFabricManifestEnabled 设置为 false 会禁止在生成过程中更新 ServiceManifest.xml。Setting UpdateServiceFabricManifestEnabled to false, will disable updates to the ServiceManifest.xml during a build. 任何更改(例如添加、删除或重命名此服务)都不会反映在 ServiceManifest.xml 中。Any change such as add, remove, or rename to the service will not be reflected in the ServiceManifest.xml. 如果进行了任何更改,则必须手动更新 ServiceManifest manually,或者将 UpdateServiceFabricManifestEnabled 临时设置为 true 并生成一个服务来更新 ServiceManifest.xml,然后将其恢复为 false。If any changes are made you must either update the ServiceManifest manually or temporarily set UpdateServiceFabricManifestEnabled to true and build the service that will update the ServiceManifest.xml and then revert it back to false.

  4. 在服务项目中将 RuntimeIndetifier 从 win7-x64 更新为目标平台。Update the RuntimeIndetifier from win7-x64 to the target platform in the service project.

    <RuntimeIdentifier>ubuntu.16.04-x64</RuntimeIdentifier>
    
  5. 在 ServiceManifest 中更新入口点程序,删除 .exe。In the ServiceManifest, update the entrypoint program to remove .exe.

    <EntryPoint> 
    <ExeHost> 
        <Program>Actor1</Program> 
    </ExeHost> 
    </EntryPoint>
    
  6. 在“解决方案资源管理器”中,右键单击该应用程序并选择“发布”。 In Solution Explorer, right-click on the application and select Publish. 此时会显示“发布”对话框。 The Publish dialog box appears.

  7. 在“连接终结点”中,选择要将其作为目标的远程 Service Fabric Linux 群集的终结点 。In Connection Endpoint, select the endpoint for the remote Service Fabric Linux cluster that you would like to target.

    publish-application

后续步骤Next steps