Service Fabric Default Publish Profile other than Local.xml

后端 未结 2 1462
隐瞒了意图╮
隐瞒了意图╮ 2021-01-14 10:33

Our company is developing our new applications using Service Fabric. A common problem we have, multiple developers use queues, databases, storages that are on remote servers

相关标签:
2条回答
  • 2021-01-14 11:25

    The VS extension for Service Fabric define a hard coded publish profile when we debug the solution using Visual Studio, it check how many nodes my cluster has and create a link to Local.5Node.xml and Local.1Node.xml depending how many nodes my cluster have.

    To accomplish the same results, we end up using custom Application Parameters per developer and each developer update the Publish Profile (Local.5node.xml) to point to their respective Application parameter files.

    It is not automated as the required feature, but can solve the main problem.

    0 讨论(0)
  • 2021-01-14 11:39

    I actually just ran into this with setting up some team specific environments. I borrowed information from the following sources:

    • Web Config Transformation
    • Replace String In File With MSBUILD

    I added multiple parameters files based on what was needed for the different teams. Each one containing their specific resource settings.

    I also added a Local.1Node.Template.xml and Local.5Node.Template.xml. I even removed the Local.1Node.xml and Local.5Node.xml from source control and set them up to be ignored while leaving them in the projects so that Visual Studio doesn't think they are truly missing. The contents of the 1Node (5Node is the same except for replacing 1Node with 5Node) are as follows:

    <?xml version="1.0" encoding="utf-8"?>
    <PublishProfile xmlns="http://schemas.microsoft.com/2015/05/fabrictools">
        <ClusterConnectionParameters />
        <ApplicationParameterFile Path="..\ApplicationParameters\Local.1Node.$(Configuration).xml" />
    </PublishProfile>
    

    I then edited the sfproj file for the Service Fabric project to contain the following MSBuild Task and Target:

    <UsingTask TaskName="ReplaceFileText" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
        <ParameterGroup>
            <InputFilename ParameterType="System.String" Required="true" />
            <OutputFilename ParameterType="System.String" Required="true" />
            <MatchExpression ParameterType="System.String" Required="true" />
            <ReplacementText ParameterType="System.String" Required="true" />
        </ParameterGroup>
        <Task>
            <Reference Include="System.Core" />
            <Using Namespace="System" />
            <Using Namespace="System.IO" />
            <Using Namespace="System.Text.RegularExpressions" />
            <Code Type="Fragment" Language="cs">
                <![CDATA[
                    File.WriteAllText(
                        OutputFilename,
                        Regex.Replace(File.ReadAllText(InputFilename), MatchExpression, ReplacementText)
                    );
                ]]>
            </Code>
        </Task>
    </UsingTask>
    <Target Name="UpdateProfile" BeforeTargets="UpdateServiceFabricApplicationManifest">
        <ReplaceFileText InputFilename="PublishProfiles\Local.1Node.Template.xml" OutputFilename="PublishProfiles\Local.1Node.xml" MatchExpression="\$\(Configuration\)" ReplacementText="$(Configuration)" />
        <ReplaceFileText InputFilename="PublishProfiles\Local.5Node.Template.xml" OutputFilename="PublishProfiles\Local.5Node.xml" MatchExpression="\$\(Configuration\)" ReplacementText="$(Configuration)" />
    </Target>
    

    The final step was to setup the different Build Configurations for the teams. I created a FT1-Debug through FT6-Debug based on the Debug configuration in the Service Fabric Service project and the Service Fabric Host project. I left all of my other projects alone.

    At this point everyone on the different teams can debug locally with the correct configuration for the cluster they are doing work in just by changing the Build Configuration and pressing F5 to debug.

    0 讨论(0)
提交回复
热议问题