0

I have many Winform(VB.Net) apps with a Local/Dev/QA/Prod environment setup. I would like to dynamically load environmental config information and access it as if it was in the app.config file using System.Configuration. I haven't found a good solution for this yet. Maybe I'm expecting too much and will have to manually deserialize the environmental config. I'm looking for ideas on how to implement this environmental config?

Here's a list of what I'd like:

  • The environmental config is a file on the file system containing an XML structure(similar to the app.config).
  • Dynamically load environmental config based on environment.
  • Environmental config can contain connection strings and other settings. Multiple additional config files is acceptable.
  • Use the built in System.Configuration calls to access the values. Basically I would like to avoid having to write a custom deserializer.

I would prefer not to use these options if possible:

  • Using a configsource parameter in the app.config to point to an external config. This would need to be edited for each environment and it would override(I think) the section where it's set.
  • Using a custom deserializer. I know this could be done and it may be the actual solution. It just seems that this should be solvable without doing this.
  • Using System.Environment isn't practical since it reads/writes to the registry for system variables.
Jon S
  • 3
  • 3
  • There are ways to use [config transformation](http://stackoverflow.com/questions/3004210/app-config-transformation-for-projects-which-are-not-web-projects-in-visual-stud) for [app.config](http://www.hanselman.com/blog/SlowCheetahWebconfigTransformationSyntaxNowGeneralizedForAnyXMLConfigurationFile.aspx) – the_lotus Jul 17 '15 at 15:52
  • Unfortunately the config transformation isn't an option. We don't want the global information to be included in the app.config file. We don't want that information to be visible in the application folder. – Jon S Jul 17 '15 at 15:58
  • timothy - I hadn't spotted that as an option when I was researching, but I don't think it will work in our case. There will be dozens of variables and our preference is to have this in a file on the network rather than adding them all into the registry. Most of these winforms are run from user computers so each computer would need the registry changes. – Jon S Jul 17 '15 at 16:04
  • I think the accepted answer here may cover what you need? http://stackoverflow.com/questions/505566/loading-custom-configuration-files Maybe not accessible through System.Configuration, but you wouldn't need to write your own deserializer either. – mikev2 Jul 17 '15 at 16:22
  • This seems like it could be what I'm looking for. I'll sift through it and see it will work. I'd tried something similar that didn't work right, but maybe this example will bring me some clarity. – Jon S Jul 17 '15 at 16:57
  • This works well for connections strings. I'm still working to get other settings read in. – Jon S Jul 20 '15 at 14:16
  • That's great - shout if you have any trouble and I'll try to help if I can. – mikev2 Jul 20 '15 at 15:14

1 Answers1

0

you can try with MSBuild, you can write your own MSBuild project file and do the tasks you mentioned. You can write c# code also by creating your own tasks and including that in your MsBuild project.

You can try with Transform XML MsBuild Task. One of the link on SO for transforming the XML using transform task.

Community
  • 1
  • 1
Abhinav Galodha
  • 9,293
  • 2
  • 31
  • 41