我有一個由針對DNX框架的項目組成的Visual Studio 2015解決方案。我一直在本地工作,但我打算部署到Azure環境(dev/test/prod)。當然,解決方案使用不同的數據庫連接字符串和其他依賴於環境的變量。在過去,我使用雲配置文件來設置這些變量,並使用CloudConfigurationManager
來讀取它們。如何使用config.json爲Visual Studio 2015/DNX項目設置環境特定的變量?
我被告知需要使用config.json文件。我在我的Startup.cs文件下面的代碼:
public Startup(IHostingEnvironment env, IApplicationEnvironment app)
{
Configuration = new ConfigurationBuilder(app.ApplicationBasePath)
.AddJsonFile("config.json")
.AddJsonFile($"config.{env.EnvironmentName}.json", optional: true)
.AddEnvironmentVariables()
.Build();
Configuration.Set("ASPNET_ENV", "Development");
}
我config.json文件是當前一個空對象{ }
。如何將變量添加到此文件(語法?),以及如何從代碼訪問它們?
您是否閱讀過http://docs.asp.net/en/latest/fundamentals/environments.html?你已經有了加載特定於環境的JSON文件的代碼 - 你有*這樣的文件嗎? –