問題:
I'm working on a C# class library that needs to be able to read settings from the web.config
or app.config
file (depending on whether the DLL is referenced from an ASP.NET web application or a Windows Forms application). 我正在使用一個C#類庫,該類須要可以從web.config
或app.config
文件中讀取設置(取決於DLL是從ASP.NET Web應用程序仍是Windows Forms應用程序引用的)。 web
I've found that 我發現 app
ConfigurationSettings.AppSettings.Get("MySetting")
works, but that code has been marked as deprecated by Microsoft. 能夠,可是該代碼已被Microsoft標記爲已棄用。 this
I've read that I should be using: 我讀過我應該使用: url
ConfigurationManager.AppSettings["MySetting"]
However, the System.Configuration.ConfigurationManager
class doesn't seem to be available from a C# Class Library project. 可是,C#類庫項目中彷佛沒有System.Configuration.ConfigurationManager
類。 spa
What is the best way to do this? 作這個的最好方式是什麼? .net
解決方案:
參考一: https://stackoom.com/question/4zPI/在-NET中從app-config或web-config讀取設置參考二: https://oldbug.net/q/4zPI/Reading-settings-from-app-config-or-web-config-in-NET