为什么exe.config已更改但vshost.exe.config未更改 [英] why exe.config changed but vshost.exe.config not changed

查看:72
本文介绍了为什么exe.config已更改但vshost.exe.config未更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试编辑app.config文件,我的代码是:

i try to edit app.config file and my code is :

var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
config.AppSettings.Settings["a"].Value = "kkkk";
 config.Save(ConfigurationSaveMode.Modified);           ConfigurationManager.RefreshSection(config.AppSettings.SectionInformation.Name);





和app.config文件是:



and app.config file is :

<configuration>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
    </startup>
  <appSettings>
    <add key="a" value="b" />
  </appSettings>
</configuration>





当我运行我的解决方案vshost.exe.config在运行时更改但当我停止我的解决方案我在vshost.exe.config中的值再次回来



i未选中启用视觉工作室托管过程中的属性

现在只是exe .config已更改,但vshost.exe.config未更改



如何在runtime上更改exe.config和vshost.exe.config



when i run my solution vshost.exe.config changed in runtime but when i stop my solution my values in vshost.exe.config come back again

i unchecked "enable the visual studio hosting process" in properties
now just exe.config changed but vshost.exe.config not changed

how can i change both exe.config and vshost.exe.config on "runtime"

推荐答案

运行vshost.exe文件时,vshost.exe.config文件会发生更改。每当从Visual Studio以调试模式运行应用程序时,都会执行vshost.exe,这就是为什么在运行修改配置文件的代码时vshost.exe.config文件正在更改的原因。但是一旦停止并重新运行应用程序,Visual Studio就会用exe.config文件替换vshost.exe.config文件,这样您在vshost.exe.config文件中的更改就会丢失。不要担心这在实际情况下你的exe文件将用于启动你的应用程序,而不是你的vshost.exe。



所以尝试直接运行应用程序来自exe的文件夹。这将仅修改exe.config文件。
the vshost.exe.config file changes when your run the vshost.exe file. Whenever you are running your application in debug mode from visual studio the vshost.exe is executed that is the reason why the vshost.exe.config file is changing when your code to modify the config file was run. but as soon as you stop and rerun your application Visual studio replaces the vshost.exe.config file with your exe.config file so your changes in vshost.exe.config file will be lost. Don't worry about this as in actual scenario your exe file will re used to launch your application and not your vshost.exe.

So try to run the application directly from folder from exe. and this will modify the exe.config file only.


我的数据formet恢复您的数据
my data formet restor your data


这篇关于为什么exe.config已更改但vshost.exe.config未更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆