如何转换XML配置预构建?

时间:2017-11-20 20:18:35

标签: c# .net visual-studio-2017 azure-service-fabric

我有一个解决方案:

Solution1
--ConfigProject
----AppManifest.xml
----ServiceManifest.xml
--Project1
--Project2

ServiceManifest.xml如下所示:

<ServiceManifest>
        ...............
  <Resources>
    <Endpoints>
      <!-- This endpoint is used by the communication listener to obtain the port on which to 
           listen. Please note that if your service is partitioned, this port is shared with 
           replicas of different partitions that are placed in your code. -->
      <Endpoint Protocol="https" Name="ServiceEndpoint" Type="Input" />
    </Endpoints>
  </Resources>
</ServiceManifest>

如果不依赖于c#代码,是否可以添加一个预构建步骤,该步骤将根据AppManifest.xml中的设置转换ServiceManifest文件中的 Resources 部分文件吗

1 个答案:

答案 0 :(得分:2)

您可以将服务清单描述如下:

<ServiceManifestImport>
    <ServiceManifestRef ServiceManifestName="Stateless1Pkg" ServiceManifestVersion="1.0.0" />
    <ConfigOverrides />
    <ResourceOverrides>
        <Endpoints>
            <Endpoint Name="ServiceEndpoint" Port="[Port]" Protocol="[Protocol]" Type="[Type]" />
            <Endpoint Name="ServiceEndpoint1" Port="[Port1]" Protocol="[Protocol1] "/>
        </Endpoints>
    </ResourceOverrides>
    <Policies>
       <EndpointBindingPolicy CertificateRef="TestCert1" EndpointRef="ServiceEndpoint"/>
    </Policies>
</ServiceManifestImport>

现在,您可以在ApplicationManifest中应用这些参数。如果需要,可以为它们添加默认值。

<Parameters>
   <Parameter Name="Port" DefaultValue="" />
   <Parameter Name="Protocol" DefaultValue="" />
   <Parameter Name="Type" DefaultValue="" />
   <Parameter Name="Port1" DefaultValue="" />
   <Parameter Name="Protocol1" DefaultValue="" />
</Parameters>

您可以使用自定义的ApplicationParameters文件(如Local1.1Node.xml和Local.5Node.xml)覆盖这些参数。另一种方法是在发布期间为每个powershell插入参数:

PS C:\> New-ServiceFabricApplication -ApplicationName fabric:/myapp -ApplicationTypeName "AppType" -ApplicationTypeVersion "1.0.0" -ApplicationParameter @{Port='1001'; Protocol='https'; Type='Input'; Port1='2001'; Protocol='http'}

了解更多详情: https://docs.microsoft.com/en-us/azure/service-fabric/service-fabric-service-manifest-resources