it:ad:nconfig:howto:configure_within_desktop_apps

IT:AD:NConfig:HowTo:Configure within Desktop Apps

You just have to remember that in desktop apps, the files have to be included in the project, in order to Content/Copied to the destination Bin…

Note that in web apps, you don't include the file in the project – Web solutions don't copy files to a sub bin).

        static void Main(string[] args)
        {

            //Local Path:
            //NConfigurator.UsingFiles("..\\..\\Config\\Custom.config", "..\\..\\Config\\Connections.config").SetAsSystemDefault();
            //Also works in Solution sharing across projects:
            NConfigurator.UsingFiles("..\\..\\Config\\Custom.config", "..\\..\\Config\\Connections.config").SetAsSystemDefault();

            Console.WriteLine(System.Configuration.ConfigurationManager.AppSettings["KeyA"]);
            Console.WriteLine(System.Configuration.ConfigurationManager.AppSettings["KeyB"]);


            Console.WriteLine(System.Configuration.ConfigurationManager.ConnectionStrings["ABC"].ConnectionString);
            Console.WriteLine(System.Configuration.ConfigurationManager.ConnectionStrings["DEF"].ConnectionString);
        }

Correctly merges the settings from SKYSW7LT and the underlying web.config:

No fuss.

  • /home/skysigal/public_html/data/pages/it/ad/nconfig/howto/configure_within_desktop_apps.txt
  • Last modified: 2023/11/04 01:50
  • by 127.0.0.1