3
votes

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, and each one has different configuration for this, all the settings are stored on ApplicationParameters file per environment, for Local development there is a single Local.5Node.xml. It is very common developers checkin their credentials and overwrite others when we get latest version of these files.

I'm trying to customize the ServiceFabric deployment script 'Deploy-FabricApplication.ps1' to use a custom PublishProfile depending on windows credentials of logged user. I can achieve that updating the deployment file, it works well when we deploy using the publish, but it seems that the default behavior of ServiceFabric when we hit F5(debug) is overwrite the parameters with a specific Local.5Node.xml application parameters.

I explored all service fabric .ps1 files and couldn't find where this is defined. I guess this is defined on .targets file, so I don't know how can I avoid this default behaviour.

Is there any other approach to use custom PublishProfiles on local development machines other than Local.5Node.xml?

2
Did you consider creating a default credential for Development? Then everyone should share the same credential for development phase and you could avoid this miss configuration issue.Fals
Why do you store settings in ApplicationParameters file and not in app.config? The second one is easily configurable for several developers with transformations, by the way.cassandrad
There is no way to use a single configuration for all developers, an very common example I can give is, our system put messages in the queue, and other service pickup the message, if multiple developers are running the application, they will pickup message from others, and the owner developer will not get these messages. Whe are using ApplicationParameters because our service is purely Service Fabric based, it works very well, we do not want to split configurations between ApplicationParamenters and AppConfigs.Diego Mendes
Today it already work with AppParam file per developer, but the problem is, only work using the Publish command, does not work when hitting F5, I think it's because the .targets is hard coded to use always Local.5Node.xml or Local.1Node.xml.Diego Mendes
It's not the targets file that is hard-coded it's the logic in the VS extension for Service Fabric Tools that hard-codes this. There's no way to modify that behavior at this time. So there's not a very good solution for accomplishing what you want except for having each developer update the parameters (manually or through your own custom automation) on their local machine each time they need them set appropriately.Matt Thalman

2 Answers

10
votes

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

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

Visual Studio Setup

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.

5
votes

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.