Developer Specific appsettings.json .net5

  • Page Owner: Not Set
  • Last Reviewed: 2025-08-26

This guide was created from: https://drengashi.com/2022/03/23/appsettings-json-for-each-developer-in-optimizely-12-and-net-5/

This implementation will allow developers to create appsettings.<ComputerNams>.json to override setting in the appsettings.json and appsettings.Development.json for local development.

1. In your web project Program.cs, add a public configuration builder property that dynamically adds an appsettings file for the developer machine name:

public static IConfiguration _configuration { get; } =
            new ConfigurationBuilder()
                .AddJsonFile("appsettings.json", false, true)
                .AddJsonFile($"appsettings.{_environment}.json", true, true)
                .AddJsonFile($"appsettings.{Environment.MachineName}.json", true, true)
                .AddEnvironmentVariables()
                .Build();

2. In the CreateHostBuilder method in Program.cs add the new configuration builder to the default builder for the development environment:

.ConfigureAppConfiguration((ctx, builder) => {
        builder.AddConfiguration(_configuration);
    })

Once this code is added, create your own appsettings file, appsettings.<ComputerName>.json in the root of your web project. Anything put in this file will override any setting in appsettings.json and appsettings.Development.json

3. Since we don't typically want to commit developer specific settings, add this to your gitignore file

appsettings.*.json
!appsettings.Development.json