简体   繁体   中英

How to transform XML configuration pre-build?

I've got a solution:

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

ServiceManifest.xml looks like this:

<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>

Without relying on c# code, is there a pre-build step that I can add that will transform the Resources section in the ServiceManifest file, based on a setting in the AppManifest.xml file?

You could describe your service manifest as following:

<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>

Now you can apply the parameters in your ApplicationManifest. If you want you can add them a default value.

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

You can override these parameters with an own customized ApplicationParameters file (like Local1.1Node.xml and Local.5Node.xml). Another alternative would be to insert the parameters per powershell during publishing:

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

For further details: https://docs.microsoft.com/en-us/azure/service-fabric/service-fabric-service-manifest-resources

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM