2

Apologies if this has been asked before; after two days of searching I can only find partial answers that don't fully relate to my situation, and are difficult to follow with my lack of experience.

I have a solution that contains four projects:

  1. Class library (containing database connection strings, email server settings, plus lots of other settings)
  2. Web application (web forms)
  3. Web application (MVC)
  4. Web API

Projects 2,3 & 4 all reference the class library, and use the database connection strings, etc, to function. These projects also contain their own additional settings in web.config, bespoke to that project.

Everything works great so far... However, I now need to publish client-specific versions of my solution, e.g. the solution for ClientABC requires different settings for each project than for ClientXYZ. All other aspects remain the same, it is simply the config settings across the four projects that need to change.

From my research, I hit upon something called SlowCheetah which transforms the config files based on the publish profile. That sounded promising, but then I get this problem, where the class library settings aren't pushed into the other projects. I can see bits of useful info in this question, but don't have the experience to apply it to my problem. I'd rather not duplicate the settings into respective project's config file if possible, as that feels messy.

Can anyone please offer me some help as to what's best here? I don't even know if I'm taking the right approach, but am pretty sure I can't be the first ask this?

Community
  • 1
  • 1
EvilDr
  • 8,943
  • 14
  • 73
  • 133
  • Related: http://stackoverflow.com/questions/4817051/can-a-class-library-have-an-app-config-file?noredirect=1&lq=1 – Maarten Oct 13 '16 at 08:56
  • Thanks. I've already read this, but I don't understand how to apply the answer(s) to my own solution, which was really my primary reason for asking. – EvilDr Oct 13 '16 at 09:00

1 Answers1

1

but then I get this problem, where the class library settings aren't pushed into the other projects

you have to keep in mind that the configuration file is readed by the SturtUp application, your client. Class Library can't run directly, but inside a WebApp or WinApp or ConsoleApp

So, any settings that you put in your ClassLibrary configuration file must be copied in the configuration file of your WebApp.

Generally, I copy some settings from app.config to web.config but, if you search on internet, you can find a method to automate this operation.

I now need to publish client-specific versions of my solution

You can create many configuration profile and use a web.config transformation:

  1. From ToolBar or Build Menu, select Configurazion Manager...

Configurazion Manager...

  1. Create all configuration you need for clients ClientABC

  2. Now you can see different web.configuration files

enter image description here

  1. Now you can specify different configurazion transformation for your ClientABC, ClientXYZ and publish them with specific configuration

EDIT: So, you can adopt this solution for your Class Library too, or external config file, and include external file in your web.config: External Config

Community
  • 1
  • 1
Glauco Cucchiar
  • 764
  • 5
  • 19
  • Hi. Yes, thanks. I understand about publish profiles and use them already. But I am trying to avoid duplicating settings across each app because that in time may lead to administration burden and errors. Is there no other way? It seems at present that putting any configuration data in the class library is a waste of time... – EvilDr Oct 13 '16 at 10:05
  • While this wasn't the answer I'd hoped for, it points me in the right direction to place settings files externally, and dynamically load them at startup using a Publish profile to isolate the correct settings files. – EvilDr Oct 20 '16 at 13:07