Sharing settings across multiple proyects RRS feed

  • General discussion

  • Hi,

    Here's my development environment:

      • Windows XP SP3
      • .NET Framework 3.5 SP1
      • VS2008 Professional SP1
      • Office 2007 SP3

      I have the following projects in my solution:

      1. A C# class library for storing common classes and extension methods
      2. A VB class library for storing data sets and table adapters
      3. A C# class library for storing shared resources and settings (access modifier is public in both cases)
      4. A VB Windows Forms application for interacting with an Access database
      5. A VB VSTO Excel template that interacts with the database in very specific ways and has a reference to the Windows Forms project

    The Windows Forms application and the VSTO Excel template share a setting and this setting is stored in the resources class library. I have no problem using the shared setting. Where I have problems is when I try to update such setting. My problem is that if I update the setting like this

    SharedSettings.Default.DbsNameDataSource = location

    The setting is updated JUST for the Windows Forms application or the VSTO Excel template, but not for both. That is, if I update the setting in Excel (or in the Windows Forms application launched from Excel), changes aren't reflected in the Windows Forms application.

    The definition of SharedSettings is

    Imports SharedSettings = SolutionNameResources.Properties.Settings

    I added the Settings file through the View Code functionality of VS2008 settings, where I put the following code in the constructor:

            /// <summary>
            /// Creates a new instance of this class.
            /// </summary>
            public Settings() 
                ConfigurationUserLevel none = ConfigurationUserLevel.None;
                Configuration exe = ConfigurationManager.OpenExeConfiguration(none);
                Debug.Print("exe = {0}", exe.FilePath);
                ConfigurationUserLevel userLocal = ConfigurationUserLevel.PerUserRoamingAndLocal;
                Configuration local = ConfigurationManager.OpenExeConfiguration(userLocal);
                Debug.Print("local = {0}", local.FilePath);
                ConfigurationUserLevel userRoaming = ConfigurationUserLevel.PerUserRoaming;
                Configuration roaming = ConfigurationManager.OpenExeConfiguration(userRoaming);
                Debug.Print("roaming = {0}", roaming.FilePath);

    When I use the shared setting, I can see that settings are stored in different files, specific to the project using them. What should I do so saving a setting in one project means saving this very same setting in the other?

    Where's the forum for this thread?

    Kind regards,

    Carlos Mallen

    Tuesday, September 4, 2012 9:42 PM

All replies