在ASP.NET中的許多人使用Web.Debug.config
/Web.Release.config
文件trasformations會是這個樣子以前的版本:如何處理調試/釋放配置轉換在ASP.NET vNext
的Web.config:
<connectionStrings>
<add name="AppDB" connectionString="Data Source=(LocalDb)\\..." />
</connectionStrings>
Web.Release.config:
<connectionStrings>
<add name="AppDB" connectionString="Data Source=(ReleaseDb)\\..." xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
</connectionStrings>
按照ASP.NET vNext tutorial您仍然可以使用Web.config。但config.json
似乎是處理配置的新途徑,現在按同一篇文章:
config.json
{
"Data": {
"DefaultConnection": {
"ConnectionString": "Server=(localdb)\\..."
}
}
}
而且在Startup.cs:
var configuration = new Configuration();
configuration.AddJsonFile("config.json");
configuration.AddEnvironmentVariables();
所以我想知道將此轉變爲json的處理config-transofrmation的建議方式是什麼?
的順序優先級是「最後獲勝」,所以使用這種方法時,你會說「默認爲default.json中的值,用環境變量中的任何內容覆蓋該值,並使用{envSpecificJson}中的任何內容覆蓋該值。推薦的方法是讓環境變量覆蓋任何基於文件的配置值。默認模板現在使用: .AddJsonFile(「appsettings.json」,可選:true,reloadOnChange:true) .AddJsonFile($「appsettings。{env.EnvironmentName} .json」,可選:true,reloadOnChange:true) .AddEnvironmentVariables(); – 2016-08-31 01:40:55