【问题标题】:How to transform XML configuration pre-build?如何转换 XML 配置预构建?
【发布时间】:2018-05-04 03:55:16
【问题描述】:

我有一个解决办法:

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 部分文件?

【问题讨论】:

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


    【解决方案1】:

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

    <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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-02-08
      • 1970-01-01
      • 2018-07-19
      • 2015-07-22
      • 2011-05-11
      • 2011-02-10
      • 2015-05-30
      • 2011-01-15
      相关资源
      最近更新 更多