Ok, this is rather simple, but from what I've seen… you can only use some sort of Windows Workflow to include another config into another (which I refuse to do).
Here's the deal:
MAINAPP.EXE References an hypothetical LIBRARY.DLL.
MAINAPP.EXE has its own MAINAPP.EXE.config.
If you add "config values" to LIBRARY.DLL (thereby creating an app.config in LIBRARY.DLL project), those values are not available at runtime even if you copy app.config into LIBRARY.DLL.config to the right path post-build.
The reason for the above is that even referenced libraries will read from the "mainapp.exe" config.
So far "so good". Now, when you add a WCF Service reference, visual studio creates or populates your app.config with the bindings/endpoints/etc.; but that's added to the project where you added the reference's config; hence, your Library.DLL.prj ends up with a nice app.config that doesn't work because it never gets read, nor even copied to the output directory. Now you may think that you can right click that app.config and set "copy always" to true. Forget it. That doesn't do anything. (You can google for that one).
So, given the above weird scenario, how is a regular VS2008 developer working with a .NET 3.5 project going to manage the WCF service references he adds to his Business Layer dll? Is that developer supposed to COPY and PASTE all the whole section from the useless app.config in his DLL to the Mainapp.exe.config file each time there's a change in the services or each time he adds/removes one ?
If you don't want to expose values, make sure you have an app. config with deployment values (empty, 0, or something). The values WILL be compiled into the DLL as default values.
Using configuration files in DLL is not trivial, but is very simple. Using configuration files in DLL is not trivial. To accomplish this, we must follow these steps: Add a reference to System.
The reason dll. config exists at all is because VS doesn't distinguish between libraries and EXEs when it needs to generate config settings. Therefore if you happen to be inside a library and VS needs to generate a config entry it'll generate it in a dll. config but that file will never be used at runtime.
Right-click on the project, select Add->New Item..., then select "Application Configuration File" from the list of possible items. Show activity on this post. It would be a template in the templates directory of Visual Studio.
Yes. Copy and paste is the answer. It's not a great answer, but it's the answer, and it has been since day 1 in .NET 1.0 with AppSettings.
You can have a library project include custom config files and those files can be copied to the executable location of another application (it's a little sticky, but not too big a deal). You just have to use OpenMappedExeConfiguration to get to any information in those files. You'd then have to do some custom coding when you instantiate your WCF proxies (instantiate a Binding and pass that to the proxy). I'm late to the party here, but I can provide more details if you're interested.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With