C# – How to best distribute client specific configuration settings

cconfiguration-managementdesktop application

I'm writing a WinForms desktop application which will be shipped out to several different clients and am wondering what the best way to implement a user configuration file is. Normally I would use the built in Settings.settings or app.config to store user settings but in this case what I want to store is unique for every client, I want it to be configured before sending it out and I want to avoid recompiling every time we ship to a new client.

What I want my config file to do is to store some information about the client specific graphics used in the program and some (hashed) passwords.

We don't suspect that the users would be hacking into anything in the program; we're just trying to avoid regular 'tech' level users from making changes or accessing certain modules that a manager should change. Up until now the password has been hardcoded and over a few years of use everyone has gotten to know what it is. We'd like to be in more control of what passwords go where but not necessarily give the clients control of the password changes.

I wrote a separate program that (de)serializes a configuration class to an XML file that would be put in the appropriate directory upon installation so that all people need to do (after I'm out of the picture) is have the .msi of the program, create an xml config file using this separate program, include the graphics they want in a sub folder and zip it all up. Then when the user unzips and installs, everything is put in the right place. When my program loads it looks for my config file to finish loading. If it can't find it it gives the user a change to locate it otherwise the program doesn't open.

I've been reading about the ConfigurationManager class but can't figure out how I could best use it. I haven't found much on people using outside configuration files and am not sure if my situation truly is unique or I'm not thinking inside the box enough. Is this a good design? Should I be doing this differently? If you have had a similar situation how have you solved it?

Best Answer

We had a similar situation where I work and used pretty much your solution. We pushed any client specific configuration into external json configuration files and load them in on program start. What we did do was to make sure that an installer would install a working default set in case the configuration files hadn't been installed on the system yet.

I'm not sure if the ConfigurationManager class would give you any benefit either as in my experience it pretty much just gives you a nice was of serializing a configuration file. Json/Xml/Whatever serialization is fairly well known and easy these days that it really comes down to personal choice.

The only addition that I've thought of is to store the configuration files on a webserver and retrieve them during install or first boot. You could specify the address during install or again on first boot. That way you don't have to supply as many files with the installer and gives you a central way to administer change to the configuration in the future.