0

我的目標是讓appsettings.json文件具有生產配置,並有可能使每個開發人員都花費很多代價。使用本地連接字符串。所以它不會類似於轉換web.config機制,我不想依賴於bulid配置。任何人都可以爲此目標提供解決方案爲ASP Core 1中的用戶自定義appsetings.json應用程序

在我過去的一個項目中,我們這樣做:我們將所有配置信息存儲在自定義config.xml中,並將其解析到自定義結構中。 Web.config僅包含服務器配置。每個開發者都擁有自己的配置文件副本和他自己的數據。解決方案是應用程序使用路徑中的配置文件,該文件通過Environment.GetEnvironmentVariable("key")在Windows環境路徑中指定。

有沒有人比我的想法更好?

回答

1

這是我如何管理配置:在代碼

public Startup(IHostingEnvironment env, IApplicationEnvironment appEnv) 
{ 

    var builder = new ConfigurationBuilder() 
     .AddJsonFile("appsettings.json"); // this one has default configuration 

    // this file name is added to my gitignore so it won't get committed, 
    // I keep local dev configuration there 
    builder.AddJsonFile("appsettings.local.overrides.json", optional: true); 

    if (env.IsDevelopment()) 
    { 
     // This reads the configuration keys from the secret store. 
     // if you need a more secure place for dev configuration use usersecrets 
     // For more details on using the user secret store see http://go.microsoft.com/fwlink/?LinkID=532709 
     builder.AddUserSecrets(); 
    } 
    // the order in which config sources is added is important, a source added later 
    // will override the same settings from a source added before 
    // environment variables is usually for production and therefore added last to give it higher priority 
    builder.AddEnvironmentVariables(); 
     Configuration = builder.Build(); 


    } 
+0

是看評論,這正是我需要的。我已經用gitignore發現了這個解決方案,但是很想回答你自己的問題。謝謝。 – user3272018

相關問題