C# – How to update appsettings.json programmatically

You have to overwrite the appsettings.json file to be able to update values programmatically. You have to deal with the whole file, not individual parts of it. The process can be summarized in the following steps: Load appsettings.json and deserialize it into an object. Update properties on the object. Serialize the object into a JSON … Read more

EF Core – How to create a database and a table

In this article, I’ll show how to use EF Core to create a database with one table in it. At the end, I’ll show a standalone console app that inserts a record into this database. Note: I’ll be using SQL Server. I haven’t tried this with other database providers. Please leave a comment if you’re … Read more

How to add User Secrets in a .NET Core console app

The User Secrets feature in .NET Core is a safe, simple way to override values in appsettings.json. The overridden values only exist in a file sitting in your own dev environment, so you don’t accidently commit them to your source control repository. This feature is enabled in ASP.NET by default, and the framework does most … Read more

C# – How to read custom configurations from appsettings.json

The appsettings.json file is a convenient way to store and retrieve your application’s configuration. You can add it to any project and then use the Microsoft.Extensions.Configuration library to work with it. Since appsettings.json is just a JSON file, you can add anything to it (as long as it’s valid JSON). Compared with working with the … Read more