请选择 进入手机版 | 继续访问电脑版

技术控

    今日:47| 主题:53603
收藏本版 (1)
最新软件应用技术尽在掌握

[其他] Different JSON files in ASP.net Core

[复制链接]
巴黎铁塔的风景 发表于 2016-10-2 12:32:18
151 1

立即注册CoLaBug.com会员,免费获得投稿人的专业资料,享用更多功能,玩转个人品牌!

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
In this article, we will learn:

  
       
  • What are configuration json files in ASP.net Core?   
  • Different configuration json files in ASP.net Core   
  • Why we need configuration.json files in ASP.net Core?  
   

Different JSON files in ASP.net Core

Different JSON files in ASP.net Core

  What are configuration json files in ASP.net Core?

  ASP.net Core is re-architected from prior versions of ASP.net,where the configuration was relying on System.Configuration and xml configurations in web.config file. In ASP.net Core, a new easy way to declare and access the global settings for solution, project specific settings,client specific settings etc..The new configuration model, works with XML,INI and JSON files.
  Different configuration json files in ASP.net Core

  There are mainly 6 configuration JSON files in ASP.net Core.
  
       
  • 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. If you will open the global.json file, you will see below code:
  1. {
  2.   "projects": [ "src", "test" ],
  3.   "sdk": {
  4.     "version": "1.0.0-preview2-003121"
  5.   }
  6. }
复制代码
projects: projects property defines the location of source code for your solution. It specifies two location for projects in the solution: src and test.src contains actual application and test contains any test.
  launchsettings.json :

  In launchsettings.json file, You can define project specific settings associated with each profile Visual Studio is configured to launch the application, including any environment variables that should be used. You can define framework for your project for compliation and debugging for specific profiles.
  1. {
  2.   "iisSettings": {
  3.     "windowsAuthentication": false,
  4.     "anonymousAuthentication": true,
  5.     "iisExpress": {
  6.       "applicationUrl": "http://localhost:50944/",
  7.       "sslPort": 0
  8.     }
  9.   },
  10.   "profiles": {
  11.     "IIS Express": {
  12.       "commandName": "IISExpress",
  13.       "launchBrowser": true,
  14.       "environmentVariables": {
  15.         "ASPNETCORE_ENVIRONMENT": "Development"
  16.       }
  17.     },
  18.     "ASPCoreMVCHelloWorld": {
  19.       "commandName": "Project",
  20.       "launchBrowser": true,
  21.       "launchUrl": "http://localhost:5000",
  22.       "environmentVariables": {
  23.         "ASPNETCORE_ENVIRONMENT": "Development"
  24.       },
  25.       "kestrel": {
  26.         "commandName": "kestrel",
  27.         "sdkVersion": "dnx-clr-win-x86.1.0.0-preview2-003121"
  28.       }
  29.     }
  30.   }
  31. }
复制代码
You can change settings for each profile via right click on the Project and then select properties.
  appsettings.json:

  ASP.NET stores application configuration settings in Web.config. ASP.NET Core uses AppSettings.json to store custom application setting, DB connection strings,Logging etc.. Below is a sample of Appsettings.json:
  1. {
  2.   "ApplicationInsights": {
  3.     "InstrumentationKey": ""
  4.   },
  5.   "Logging": {
  6.     "IncludeScopes": false,
  7.     "LogLevel": {
  8.       "Default": "Debug",
  9.       "System": "Information",
  10.       "Microsoft": "Information"
  11.     }
  12.   }
  13. }
复制代码
bundleconfig.json

  You can define the configuration for bundling and minification for the project.
  1. // Configure bundling and minification for the project.
  2. // More info at https://go.microsoft.com/fwlink/?LinkId=808241
  3. [
  4.   {
  5.     "outputFileName": "wwwroot/css/site.min.css",
  6.     // An array of relative input file paths. Globbing patterns supported
  7.     "inputFiles": [
  8.       "wwwroot/css/site.css"
  9.     ]
  10.   },
  11.   {
  12.     "outputFileName": "wwwroot/js/site.min.js",
  13.     "inputFiles": [
  14.       "wwwroot/js/site.js"
  15.     ],
  16.     // Optionally specify minification options
  17.     "minify": {
  18.       "enabled": true,
  19.       "renameLocals": true
  20.     },
  21.     // Optinally generate .map file
  22.     "sourceMap": false
  23.   }
  24. ]
复制代码
project.json:

  Asp.net Core uses Project.JSON file for storing all project level configuration settings.The Project.json file stores configuration information in JSON format.
  1. {
  2.   "dependencies": {
  3.     "Microsoft.NETCore.App": {
  4.       "version": "1.0.0",
  5.       "type": "platform"
  6.     },
  7.     "Microsoft.ApplicationInsights.AspNetCore": "1.0.0",
  8.     "Microsoft.AspNetCore.Diagnostics": "1.0.0",
  9.     "Microsoft.AspNetCore.Mvc": "1.0.0",
  10.     "Microsoft.AspNetCore.Razor.Tools": {
  11.       "version": "1.0.0-preview2-final",
  12.       "type": "build"
  13.     },
  14.     "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
  15.     "Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
  16.     "Microsoft.AspNetCore.StaticFiles": "1.0.0",
  17.     "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
  18.     "Microsoft.Extensions.Configuration.Json": "1.0.0",
  19.     "Microsoft.Extensions.Logging": "1.0.0",
  20.     "Microsoft.Extensions.Logging.Console": "1.0.0",
  21.     "Microsoft.Extensions.Logging.Debug": "1.0.0",
  22.     "Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0",
  23.     "Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0"
  24.   },
  25.   "tools": {
  26.     "BundlerMinifier.Core": "2.0.238",
  27.     "Microsoft.AspNetCore.Razor.Tools": "1.0.0-preview2-final",
  28.     "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final"
  29.   },
  30.   "frameworks": {
  31.     "netcoreapp1.0": {
  32.       "imports": [
  33.         "dotnet5.6",
  34.         "portable-net45+win8"
  35.       ]
  36.     }
  37.   },
  38.   "buildOptions": {
  39.     "emitEntryPoint": true,
  40.     "preserveCompilationContext": true
  41.   },
  42.   "runtimeOptions": {
  43.     "configProperties": {
  44.       "System.GC.Server": true
  45.     }
  46.   },
  47.   "publishOptions": {
  48.     "include": [
  49.       "wwwroot",
  50.       "Views",
  51.       "Areas/**/Views",
  52.       "appsettings.json",
  53.       "web.config"
  54.     ]
  55.   },
  56.   "scripts": {
  57.     "prepublish": [ "bower install", "dotnet bundle" ],
  58.     "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
  59.   }
  60. }
复制代码
Please Note, Microsoft has decided to move .NET Core projects to .csproj/MSBuild so all .NET projects will use the same tooling and build system. Starting in .NET Core RTM/tooling preview 2, Visual Studio will automatically rename .xproj files as .csproj.
  bower.json :

  Bower is a package manager for the web. Bower manages components that contain HTML, CSS, JavaScript, fonts or even image files. Bower installs the right versions of the packages you need and their dependencies. With ASP.NET core, jQuery and bootstrap packages are already installed and bower, gulp and NPM are already in place.Client-side packages are listed in the bower.json file.
  Summary:

  In this article, we have discussed:
  
       
  • What are configuration json files in ASP.net Core?   
  • Different configuration json files in ASP.net Core   
  • Why we need configuration.json files in ASP.net Core?  
  Thanks for visiting !!
   © 2016,CsharpStar. All rights reserved.



上一篇:微服务场景下的自动化测试
下一篇:RcppAnnoy 0.0.8
谷弟 发表于 2016-10-9 11:13:28
系统居然说我是在灌水,我有吗?
回复 支持 反对

使用道具 举报

*滑动验证:
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

我要投稿

推荐阅读

扫码访问 @iTTTTT瑞翔 的微博
回页顶回复上一篇下一篇回列表
手机版/CoLaBug.com ( 粤ICP备05003221号 | 文网文[2010]257号 )

© 2001-2017 Comsenz Inc. Design: Dean. DiscuzFans.

返回顶部 返回列表