2

I'm trying to do a web application using Asp.Net Core but I realized don't have the appsettings.json by default file like this project.

enter image description here

Currently, my project is like this:

enter image description here

I need the appsettings.json to put the ConnectionString of the database.

So someone knows why I don't have the appsettings.json file by default? and How I can create this file? another question is what is the appsettings.Development.json file in the first image?

My Program.cs is this

public class Program
    {
        public static void Main(string[] args)
        {
            CreateWebHostBuilder(args).Build().Run();
        }

        public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
            WebHost.CreateDefaultBuilder(args)
                .UseStartup<Startup>();
    }

1 Answer 1

3

You can manually add a JSON file named appsettings.json to the project's root folder. The template appsettings.json is like this:

{
    "ConnectionStrings": {
        "ConnectionName": "your connection string"
    },
    "Logging": {
        "IncludeScopes": false,
        "LogLevel": {
            "Default": "Warning"
        }
    }
}

Also, you can provide multiple setting files for each environment. For example, when you are running your app in the development environment you can set a connections string for the development database. The naming convention for appsettings.json file is appsettings.Environment.json.

Sign up to request clarification or add additional context in comments.

4 Comments

but I see the "appsettings.Enviroment.json" is a sub-file of "appsettings.json" file. How i can do that sub-file?
Yes, Visual Studio shows them as a group of settings. But they are simple and independent files as you can see using a file explorer. So create 2 separate files: "appsettings.json" and "appsettings.Development.json" in the project folder and include them in the project. The result will be as you expect.
thanks man, you save my sad saturday! last question: I need create "appsettings.Production.json" file?
No, appsettings.json applies to all environments. But if you are using an environment-based appsettings.Environemnt.json, it's settings will override appsettings.json in that specific environment.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.