Update: Single connection string for Multiple Developers

https://dcdevs.blogspot.com/2017/06/single-connection-string-for-multiple.html

If you have implemented the trick above, you may have noticed it has stopped working when you moved to a .NET Core project. This is because the DB connection alias is achieved via registry keys which is a Windows-specific behavior. .NET Core supports cross platform development, so Microsoft elected not to implement this Windows-only feature.

However, .NET Core provides a new way to manage such configurations across developers - user secrets. In Visual Studio, right click on the project that contains your appsettings.json file and navigate to manage user secrets. User secrets are machine only - Visual Studio will not try to check them in to source control.


Here, you can mimic the structure of your appsettings.json to overwrite any configuration setting - not just the connection string! Any values you define here will overwrite the corresponding appsettings.json value (hierarchy must match).

Next, you'll need to create a C# class that contains a property for each setting you will overwrite via user secrets. Below, I have created a class that will be used to overwrite my connection string.


Finally, add the following snippet of code to your Program.cs file. This function overwrites the appsettings.json file with the fields you specified in the C# file with data from your UserSecrets.json file.


You can repeat this process for as many configuration settings as you want - just add the JSON in UserSecrets and a corresponding field in UserSecrets.cs

Thanks for reading!

Comments

Popular posts from this blog

ASP.NET Identity Remember Me

IIS Express Client Certificates

ASP.NET MVC - How to enable/disable CaC/Client Certificate authentication per area or route.