ASP.net Core是从之前的ASP.net版本重新架构的,其中包括配置 依赖于 web.config 文件中的 System.Configuration 和 xml 配置。 在 ASP.net Core 中,一种声明和访问全局设置的新简单方法 解决方案、项目特定设置、客户端特定设置等。新的配置模型, 适用于 XML、INI 和 JSON 文件。
ASP.net Core 中的不同配置 json 文件 ASP.net Core 中主要有 6 个配置 JSON 文件。
global.json
launchsettings.json
appsettings.json
bundleconfig.json
project.json
bower.json
global.json
示例
You can define the solution level settings in global.json file.{
"projects": [ "src", "test" ],
"sdk": {
"version": "1.0.0-preview2-003121"
}
}
projects − projects属性定义了解决方案中源代码的位置。
指定解决方案中项目的两个位置:src和test.src包含实际的 应用程序和测试包含任何测试。launchsettings.json
在launchsettings.json文件中,您可以定义与项目相关的特定设置 每个配置文件 Visual Studio 都配置为启动应用程序, 包括应使用的任何环境变量。您可以定义框架 为您的项目进行特定配置文件的编译和调试。
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:50944/",
"sslPort": 0
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"ASPCoreMVCHelloWorld": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"kestrel": {
"commandName": "kestrel",
"sdkVersion": "dnx-clr-win-x86.1.0.0-preview2-003121"
}
}
}
}
您可以通过右键单击项目,然后选择来更改每个配置文件的设置
appsettings.json
ASP.NET 将应用程序配置设置存储在 Web.config 中。 ASP.NET 核心 使用 AppSettings.json 存储自定义应用程序设置, 数据库连接字符串、日志记录等。以下是 Appsettings.json 的示例 -
{
"ApplicationInsights": {
"InstrumentationKey": ""
},
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
}
}
}
bundleconfig.json
您可以定义项目的捆绑和缩小配置。
[
{
"outputFileName": "wwwroot/css/site.min.css",
// An array of relative input file paths. Globbing patterns supported
"inputFiles": [
"wwwroot/css/site.css"
]
},
{
"outputFileName": "wwwroot/js/site.min.js",
"inputFiles": [
"wwwroot/js/site.js"
],
// Optionally specify minification options
"minify": {
"enabled": true,
"renameLocals": true
},
// Optinally generate .map file
"sourceMap": false
}
]
project.json
Asp.net Core使用Project.JSON文件来存储所有项目级配置
settings.The Project.json文件以JSON格式存储配置信息。{
"dependencies": {
"Microsoft.NETCore.App": {
"version": "1.0.0",
"type": "platform"
},
"Microsoft.ApplicationInsights.AspNetCore": "1.0.0",
"Microsoft.AspNetCore.Diagnostics": "1.0.0",
"Microsoft.AspNetCore.Mvc": "1.0.0",
"Microsoft.AspNetCore.Razor.Tools": {
"version": "1.0.0-preview2-final",
"type": "build"
},
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
"Microsoft.AspNetCore.StaticFiles": "1.0.0",
"Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
"Microsoft.Extensions.Configuration.Json": "1.0.0",
"Microsoft.Extensions.Logging": "1.0.0",
"Microsoft.Extensions.Logging.Console": "1.0.0",
"Microsoft.Extensions.Logging.Debug": "1.0.0",
"Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0",
"Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0"
}
}
bower.json
Bower是一个用于web的包管理器。Bower管理包含组件的内容 HTML、CSS、JavaScript、字体甚至图像文件。 Bower 安装正确的版本 您需要的包及其依赖项