asp.net-core - .NET Core Web 应用程序项目中缺少默认的 "appsettings.json"文件

标签 asp.net-core

我正在尝试使用 Asp.Net Core 制作一个 Web 应用程序,但我意识到默认情况下没有像这个项目这样的 appsettings.json 文件。

enter image description here

目前,我的项目是这样的:

enter image description here

我需要appsettings.json来放置数据库的ConnectionString。

那么有人知道为什么我默认没有 appsettings.json 文件吗?以及如何创建此文件? 另一个问题是第一张图片中的 appsettings.Development.json 文件是什么?

我的Program.cs是这个

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

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

最佳答案

您可以手动将名为 appsettings.json 的 JSON 文件添加到项目的根文件夹中。模板appsettings.json是这样的:

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

此外,您可以为每个环境提供多个设置文件。例如,当您在开发环境中运行应用程序时,您可以为开发数据库设置连接字符串。 appsettings.json 文件的命名约定为 appsettings.Environment.json

关于asp.net-core - .NET Core Web 应用程序项目中缺少默认的 "appsettings.json"文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61432931/

相关文章:

c# - .NET Core 中的异步日志记录范围

iis - IIS中ASP.NET Core应用程序内部的虚拟目录

c# - 如何在 ASP.NET Core 中使用 npm

reactjs - 识别 SPA 和 .NET Core 3 的角色

asp.net-core - 我们如何将 Asp.net Core Identity 与 Cosmosdb(sqlapi) 一起使用

asp.net-core - 为 EF、AddDbContext 或 AddEntityFramework 添加服务

reactjs - JWT LocalStorage 与 Cookie

asp.net-web-api2 - 以新的 ASP.NET vnext Web api 方式访问 Request.Content?

sql-server - Entity Framework 核心在 c# 中将 float(db 数据类型)转换为 double 时添加数字

c# - Serilog Logcontext 属性在异常处理程序之后消失了