C# 類庫 讀取 app.dll.config 配置文件的問題

app.config文件僅供exe工程讀取的,想多數操作一樣,使用 ConfigurationManager.AppSettings["key"]   就可以正常讀取。

在調試dll工程時,需要單獨指定config文件才能正確讀取key值。

 static string configPath = System.Reflection.Assembly.GetExecutingAssembly().Location.ToString() + ".config";
        static Configuration MyConfiguration = ConfigurationManager.OpenMappedExeConfiguration(new ExeConfigurationFileMap()
            {
                ExeConfigFilename = configPath
            }, ConfigurationUserLevel.None);
        private string IP = MyConfiguration.AppSettings.Settings["IPAddr"].Value;       
        private int Port = Int32.Parse(MyConfiguration.AppSettings.Settings["Port"].Value);


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章