I have a situation, where my program (C#, ASP.NET Core Web API) is used by various customers and they all have slightly different setups. They all use different connection strings, and some only have a production environment and some have both test and production environments. And from time to time I have to attach to their system from Visual Studio, so I can debug the code.
Here is what I’m do right now. Let me know if you have any suggestions or better ideas.
I have a serviceconfiguration.json
file with configuration shared accross all setup.
My appsettings.json
contains the settings I’m using when running in Visual Studio. When have to debug a customer, I manually change values in appsettings.json
so they match the customer.
I have a seperate settings file for each customer+setup (placed in /Properties/PublishingProfiles
)
- customer_a_sandbox.appsettings.json
- customer_a_production.appsettings.json
- customer_b.appsettings.json
I also have publishing profile for each customer+setup.
- customer_a_sandbox.pubxml
- customer_a_production.pubxml
- customer_b.pubxml
In each .pubxml
I have added (replace customer_a_sandbox
for the relevant configuration):
<ItemGroup>
<Content Remove="appsettings.json"/>
<ResolvedFileToPublish Include=".PropertiesPublishingProfilescustomer_a_sandbox.appsettings.json">
<RelativePath>appsettings.json</RelativePath>
</ResolvedFileToPublish>
</ItemGroup>
And finally, I have this is my c# code:
builder.Configuration.AddJsonFile("serviceconfiguration.json", false);
To build for a customer I run:
dotnet publish -p:PublishProfile="customer_a_sandbox" -o publishedFiles
I’m thinking that I cannot be the first developer, that face this situation where multiple customers use the same program but with various configurations.
How do you handle individual configurations for each customer?