技术控

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

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

[复制链接]
巴黎铁塔的风景 发表于 2016-10-2 12:32:18
96 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-1 (settings,solution,specific,article,relying)

  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:
  [code]{
  "projects": [ "src", "test" ],
  "sdk": {
    "version": "1.0.0-preview2-003121"
  }
}
[/code]  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.
  [code]{
  "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"
      }
    }
  }
}
[/code]  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:
  [code]{
  "ApplicationInsights": {
    "InstrumentationKey": ""
  },
  "Logging": {
    "IncludeScopes": false,
    "LogLevel": {
      "Default": "Debug",
      "System": "Information",
      "Microsoft": "Information"
    }
  }
}
[/code]  bundleconfig.json

  You can define the configuration for bundling and minification for the project.
  [code]// Configure bundling and minification for the project.
// More info at https://go.microsoft.com/fwlink/?LinkId=808241
[
  {
    "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
  }
]
[/code]  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.
  [code]{
  "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"
  },

  "tools": {
    "BundlerMinifier.Core": "2.0.238",
    "Microsoft.AspNetCore.Razor.Tools": "1.0.0-preview2-final",
    "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final"
  },

  "frameworks": {
    "netcoreapp1.0": {
      "imports": [
        "dotnet5.6",
        "portable-net45+win8"
      ]
    }
  },

  "buildOptions": {
    "emitEntryPoint": true,
    "preserveCompilationContext": true
  },

  "runtimeOptions": {
    "configProperties": {
      "System.GC.Server": true
    }
  },

  "publishOptions": {
    "include": [
      "wwwroot",
      "Views",
      "Areas/**/Views",
      "appsettings.json",
      "web.config"
    ]
  },

  "scripts": {
    "prepublish": [ "bower install", "dotnet bundle" ],
    "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
  }
}
[/code]  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-2016 Comsenz Inc. Design: Dean. DiscuzFans.

返回顶部 返回列表