Override appSettings during development – .NET Core
Tags: net, netcore, aspnetcore, visualstudio
Published: 2019-02-22 15:14:11

---
title: Override appSettings during development – .NET Core
published: true
tags: .NET,.NET Core,ASP.NET Core,Visual Studio
canonical_url: https://ankitvijay.net/2018/12/28/override-appsettings-during-development-net-core/
---

Sometime back, I had written about [how to override appSettings](https://dev.to/vijayankit/override-appsettings-during-development-2baj-temp-slug-7335002) during development in traditional ASP.NET application.

Recently, we started development of a ASP.NET Core application and had a similar challenge. Our developers work on different operating systems (Windows and Mac). They have different local connection strings and application settings. We had a same problem as earlier: How do we ensure that we do not store developer specific app settings/ connection string in source control.

Configuration in ASP.NET Core is quite [advance and extensible](https://docs.microsoft.com/en-us/aspnet/core/fundamentals/configuration/?view=aspnetcore-2.2) as compared to traditional ASP.NET Framework. We have multiple ways to solve this problem. From the documentation:

> App configuration in ASP.NET Core is based on key-value pairs established by _configuration providers_. Configuration providers read configuration data into key-value pairs from a variety of configuration sources:
> 
> - Azure Key Vault
> - Command-line arguments
> - Custom providers (installed or created)
> - Directory files
> - Environment variables
> - In-memory .NET objects
> - Settings files

Also, ASP.NET Core offers following [two recommended](https://docs.microsoft.com/en-us/aspnet/core/security/app-secrets?view=aspnetcore-2.2&tabs=windows) ways to store app secrets during development:

- Environment variables
- Secret Manager

One of the issue, with the above two approaches is that the settings are stored outside the IDE. Also, since these settings override the `appSettings.json file` it can cause confusion while debugging as the developer may not realize that settings are being overridden.

## Our Approach

For our project we were looking for the simplest possible solution without any additional overhead. The easiest possible solution us for was to use `appSettings.Developement.json` file to store local settings and exclude it from source control by adding to `.gitignore` (we use Git).

However, we already have a separate “`Dev`” environment where we first deploy our application before pushing to `Test` and `Live` environments. Using the default `Developement` environment for the purpose of storing the local settings could have confused the developers.

As a result, we ended up adding a new **`appSettings.Local.json`** file to the project. This setting file was then added to `.gitignore` to exclude this file from source control.

<script src="https://gist.github.com/ankitvijay/21b45c70e00846d5ce738005fae0372b.js"></script>

Here is a sample `appSettings.Local.json`

<script src="https://gist.github.com/ankitvijay/8d86bdc4bf62b95fa4e16601fd970813.js"></script>

We then, changed our `launchsettings.json` and updated `ASPNETCORE_ENVIRONMENT` to point to `Local` instead of `Development`

Last but not the least, we updated `Startup.json` to use developer exception page while doing development.

<script src="https://gist.github.com/ankitvijay/368ea6031ed1d31c9c907f9d8fe2f009.js"></script><amp-fit-text layout="fixed-height" min-font-size="14" max-font-size="48" height="50"><p>That’s it! This approach helped us to keep all our settings in one place (within our IDE) and it turned out to be a pretty neat solution to our problem.</p></amp-fit-text>

Hope you find this tip useful. Please share your thoughts in comments section below.

The post [Override appSettings during development – .NET Core](https://ankitvijay.net/2018/12/28/override-appsettings-during-development-net-core/) appeared first on [Hi, I'm Ankit](https://ankitvijay.net).