4

When I compile the library, all the settings in Settings.Settings are integrated into the DLL. how do I prevent this?

Eli Perpinyal
  • 1,706
  • 3
  • 19
  • 35
  • What is it you are trying to achieve? The *default* values are integrated into the DLL, but at runtime the configuration system will first check the exename.config file (or the user settings paths) for any modified values. What you want to happen by not integrating the defaults in the dll? – Simon P Stevens Jan 12 '11 at 12:45
  • My goal is to be able to change the setting after compilation and deployment simply by modifying the app.config. There is no app.config so i'm assuming it is using the closest app.config to the .exe (in the same folder) Is there a way to use two app.configs. if not do i need to stop using settings.settings? – Eli Perpinyal Jan 12 '11 at 12:57

3 Answers3

3

View the properties of the Settings.settings file and set the Build Action to Resource, Copy to Output Directory to Do Not Copy.

This should create you a dll.config file where you can edit the settings outside of building.

delimited
  • 263
  • 1
  • 6
  • Thanks. When my application is using the DLL, will the DLL use whatever settings are in the dll.config? – Eli Perpinyal Jan 12 '11 at 12:58
  • The compilation of the Settings file creates a Designer.cs code file which you can open in VS and see that it will retrieve values from the xml config file. VS should synchronise this and handle serialization for you also. – delimited Jan 12 '11 at 13:01
  • @Eli - No. You need to move all your settings over to the application's app.config. The settings are per application, not per library. People often write their own configurations because of weaknesses in `System.Configuration` like this. – Mark H Jan 12 '11 at 13:01
  • @Sparkie Sorry but the settings will be put into the app.config - have you tried it? – delimited Jan 12 '11 at 13:07
  • VS will not copy over settings from a dll's app.config to the application's app.config. (Unless they've added that recently). You need to copy them over manually. – Mark H Jan 12 '11 at 13:08
  • Perhaps they have, but having done it in VS2010, the app.config is where the settings and values are kept. – delimited Jan 12 '11 at 13:11
  • @delimited: yes, if you compile a dll alone, it'll make an app.config, which will be output as .dll.config. However - this config file is never used in an application that utilises the DLL. A dll shares it's configuration file with the application that uses it, so the .dll.config is useless. – Mark H Jan 12 '11 at 13:19
0

Don't have any settings listed in Settings.Settings. If you don't want them being shipped out in the dll, then don't have them. If you have them, then you must need them for something, in which case it makes no sense not to include them.

Joel Etherton
  • 37,325
  • 10
  • 89
  • 104
0

If you don't want to expose values, make sure you have an app.config with deployment values (empty, 0, or something). The values WILL be compiled into the DLL as default values.

Scoregraphic
  • 7,110
  • 4
  • 42
  • 64