使.exe文件使用在上一个程序会话中更新的设置值 [英] Making the .exe file use the setting value updated in the previous program session

查看:89
本文介绍了使.exe文件使用在上一个程序会话中更新的设置值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

在程序中,我有一个字符串类型的设置.我需要在运行时更改或更新其值.为了在下一个程序会话中访问更新后的值,我使用下面的代码保存了更新后的值.在Visual Studio环境中的下一个会话中运行程序(通过按F5按钮)时,它运行良好,并使用了设置的最后更新值,但是当按下Ctrl + F5或Visual Studio之外的.exe文件时,执行Studio环境后,它会忽略设置的最后更新值(在上一个程序会话中设置),而是使用在设计时设置的默认值.请告诉我如何使exe文件使用更新后的设置在下一个程序会话中使用它的值而不是其设计时间值?

非常感谢

Hello,

In a program I have a setting of string type. I need to change or update its value at runtime. In order to I could access to the updated value in the next program session, I save the updated value using the code below. When the program is run (by pressing F5 button) in the next session inside the Visual studio Environment, it works well and uses the last updated value of the setting, but when Ctrl+F5 is pressed or when the .exe file outside of Visual studio Environment is executed, it ignores the last updated value of the setting (set at last program session), and the default value set at design time is used instead.Could you please tell me how I could make the exe file use the updated setting value instead of its design time value in the next program session?

Thanks a lot

Properties.Settings.Default.MySetting = "NewValue";
Properties.Settings.Default.Save();

推荐答案

代码看起来不错.
您的设置保存在项目的bin/debug和/或bin/release目录中的[yourapp] .exe.config文件中.
最初,这些值是从项目中的app.config文件复制的.
此文件(app.config)具有复制到Ouput目录"属性.
如果此属性的值为始终复制",它将恢复原始值.
我怀疑您正在遭受这个问题的困扰.

干杯
The code looks OK.
Your settings are saved in a file [yourapp].exe.config in the bin/debug and/or bin/release directory of your project.
Originally the values are copied from the app.config file IN your project.
This file (app.config) has a property "Copy to Ouput Directory".
If this property has a value of "Copy Always" it restores the original value.
I suspect you are suffering from that problem.

Cheers


不,不是那样的-调试和发布应用程序不同,因此配置文件也不同.看一下项目中的"bin"文件夹,您将看到两个YourProject.exe.config文件-一个在debug文件夹中,一个在发行版中.如有必要,请对其进行编辑,但请仔细考虑:大多数时候,您绝对不希望调试系统处理发布数据...
Nope, it don''t work like that - the debug and release applications are different and so have different config files. Have a look at the "bin" folder in your project and you will see two YourProject.exe.config files - one in the debug folder, and one in the release. Edit them if you have to, but think about it: most of the time you definitely don''t want the debug system working on release data...


这篇关于使.exe文件使用在上一个程序会话中更新的设置值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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