日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

C#之app.config、exe.config和vshost.exe.config作用区别

發布時間:2023/12/10 45 豆豆
生活随笔 收集整理的這篇文章主要介紹了 C#之app.config、exe.config和vshost.exe.config作用区别 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.


vshost.exe.config是程序運行時的配置文本?
exe.config是程序運行后會復制到vshost.exe.config?
app.config是在vshost.exe.config和exe.config沒有情況起作用,從app.config復制到exe.config再復制到vshost.exe.config

寫配置文件都是寫到exe.config文件中了,app.config不會變化。?
app.config只在exe.config丟失的情況下在開發環境中重新加載app.config,vshost.exe.config和exe.config會自動創建內容跟app.config一樣。

vshost.exe.config和app.config兩個文件可不要,但exe.config文件不可少。

網絡上有很多文章是講app.config讀寫方法的,可是事實上這個文件程序就不能改變它。下面是動態修改配置文件的方法:


    public static void SaveAppSettings(string aKey, string aValue)
{
// 創建配置文件對象
string file = System.Windows.Forms.Application.ExecutablePath;

//此處修改為.vshost.exe.Config的內容
// System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(file);


if (config.AppSettings.Settings[aKey] != null)
{
// 修改
config.AppSettings.Settings[aKey].Value = aValue;
}
else
{
// 添加
AppSettingsSection ass = (AppSettingsSection)config.GetSection("appSettings");
ass.Settings.Add(aKey, aValue);
}

// 保存修改
config.Save(ConfigurationSaveMode.Modified);

// 強制重新載入配置文件的連接配置節
ConfigurationManager.RefreshSection("appSettings");
}


原文:https://www.cnblogs.com/ShaYeBlog/p/8303776.html

總結

以上是生活随笔為你收集整理的C#之app.config、exe.config和vshost.exe.config作用区别的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。