Problem
One example might be when one creates a dynamic linked library (dll) and a windows or web application. Trying to reference the settings in specific configuration files has been a problem in the past. Using Visual Studio 2008, I was able to resolve this issue.
Solution
So for example:
(Within Project Class Files)
namespace company.dllLibrary //used within my dll project.
namespace company.service //used within my exe project.
Settings.cs (dll project):
I've found that within the Settings.cs of the distinct projects I had to add the following statement for settings to be updated properly:
(within the setter for the specific property related to the setting)
name = value;
this.Save(); //added this to ensure setting is saved when I update the property
To read information directly from within my dll or exe project I simply leverage the appropriate namespace:
var x = company.dllLibrary.Properties.Settings.Default.SettingName;
company.dllLibrary.Properties.Settings.Default.SettingName = value;
When I want to save a value I can assign to it from within either my dll or exe project:
company.dllLibrary.Properties.Settings.Default.SettingName = value; //string, DateTime, etc
Caveats
It appears that one ought to finalize all settings within the Settings Pane because the IDE may overwrite setters/getters. I see no limit on the umber of workspaces one might leverage in this way.
Naturally if I want to reference files in alternate namespaces I could just:
company.service.Properties.Settings.Default.SettingName = value;
Impportant Note - I had to review the project properties to verify that my startup method and default namespace referenced the updated namespace. I also needed to review each of the associated xml for the app.config files to ensure that the proper namespaces were referenced in the config sections.
Hope this helps!
1 comments:
I've realized that probably one of the better ways out of the config hell of Visual Studio (substituted for the dll hell we used to experience) is the use of a configuration table on the datastore. I've used this in the past and with LINQ 2 SQL it seems to make even more sense (given ease of access).
Post a Comment