更改.NET应用程序设置,而无需重新编译 [英] Changing .NET application settings without recompiling

查看:103
本文介绍了更改.NET应用程序设置,而无需重新编译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个窗口服务,是引用另一个组件(类库)。在这个其他组件我用的应用程序设置来存储一些值。当我所有需要的文件复制到服务器上,我可以看到在 AssemblyName.dll.config 文件中的这些设置。

I have a windows service that is referencing another assembly (class library). In this other assembly I used Application Settings to store some values. When I copy all the required files to the server I can see these settings in AssemblyName.dll.config file.

不过,当我改变这个配置文件中的设置并重新启动服务的变化没有影响。即使我卸载/重新安装该服务仍然在运行时返回旧的值。

However, when I change a setting in this config file and restart the service the change has no effect. Even if I uninstall/reinstall the service it still returns the old value at runtime.

配置文件:

   <setting name="RecordLimit" serializeAs="String">
     <value>300</value>
   </setting>

code:

Code:

if (recordCount > Settings.Default.RecordLimit) //always 300

所以,即使我更改配置文件,以400的值,然后重新启动甚至重新安装该服务,该值始终是300让我觉得这个值存储在并从编译code返回。

So even if I change the value in the config file to 400 and restart or even reinstall the service, the value is always 300 making me think that this value is stored in and returned from the compiled code.

我在做什么错的,是有可能,更改应用程序设置总是需要重新编译和重新安装(我明白,我可以使用保存()方法来改变但是这是一个Windows服务,因此采用这种方法似乎从code设置不使意义上的)?

What am I doing wrong and is it possible that changes to application settings always require a recompile and reinstall (I understand that I can use Save() method to change the settings from code but this is a windows service so using this method doesn't seem to make sense)?

如果这些设置保存在配置文件中没有任何效果和设置存储在编译code,我可以放心地删除这些配置文件?

If these settings stored in the config file have no effect and the settings are stored in the compiled code, can I safely remove these config files?

如果这些设置不能在没有重新编译我要保存设置,我可以更改,恕不recompling其他选项可以更改吗?

If these settings cannot be changed without recompiling what other options I have to store setting that I can change without recompling?

编辑:我只是删除了 AssemblyName.dll.config 文件和C返回300这样的配置文件是无关紧要的$ C $显然

I just removed the AssemblyName.dll.config file and the code returned 300 so the config file is irrelevant apparently.

推荐答案

据我知道如何配置文件工作,它必须在EXE级别:appname.exe.config为服务/应用程序和web.config中网站/服务。

As far as I know how config files work, it has to be at the EXE level: appname.exe.config for services/apps and web.config for web sites/services.

请参阅问题/答案在<一个href="http://stackoverflow.com/questions/1188681/can-someone-provide-a-quick-app-config-web-config-tutorial">Can有人提供了一个快速的App.config / Web.config中教程?的参考。

See question/answers at Can someone provide a quick App.config/Web.config tutorial? for reference.

这篇关于更改.NET应用程序设置,而无需重新编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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