繁体   English   中英

App.Config 中的 appSettings 值在 VS 2015 和 VS 2017 中有所不同

[英]appSettings value in App.Config differ in VS 2015 and VS 2017

这是VS 2015的正常行为吗?

我正在尝试在 App.Config 的 appSettings 中存储一个值。 在 VS 2017 中,它存储在 WindowsFormsApplication1.exe.config 中,但它没有将值存储在 VS 2015 中

我的代码与两个版本的 VS 中的代码相同。

        var conf = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
        var settings = conf.AppSettings.Settings;
        settings.Add("password", textBox1.Text);
        conf.Save(ConfigurationSaveMode.Modified);
        ConfigurationManager.RefreshSection(conf.AppSettings.SectionInformation.Name);

我的 App.config 是这样的:

 <?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <startup> 
      <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
    </startup>
<appSettings>

</appSettings>
</configuration>

对此有何解释?

我相信构建程序时生成的 WindowsFormsApplication1.exe.config 文件是出于调试目的。

试试这个,看看配置文件所在的路径。 取自这个答案

    using System.Configuration;  // Add a reference to System.Configuration.dll
    ...
    var path = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal).FilePath;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM