Search code examples
c#winforms.net-2.0

Application Settings based on Configuration Using Build Events


I have three configurations created. "Development", "Test", "Production". Configuration Manager

I also have a database connection string defined in my settings Settings

Is there a way I can utilize the following screen to ensure the proper value ends up in the setting field for each configuration? enter image description here

And is the same possible for a class library housing an entity model?


Solution

  • I can offer you three options.

    1) Use $(ConfigurationName) in your pre-build passing it into a batch file or the like.

    2) Use a config files with separate sections for each build configuration. VS supports this. I think this is the best option. See below.

    e.g. enter image description here

    3) In each project configuration declare a unique compilation symbol and use that in code for conditional compilation (not recommended).