How to include app.config file of a DLL plugin in EXE build

My application references several DLL’s. Some of these DLL’s get their data from Web service. You might already know that the WebRefrence URI will be saved in config file. This config file will also be available in DLL’s bin folder. But when we add reference to the DLL in EXE, these DLL specific config files are lost. Therefore, before you build & send the EXE, you need to make sure that the given WebService Url is reachable by the target PC.

Recently, I had a problem with this. I package my application and deliver it to an external user. The user’s webservice url is different from what I configured which building. Practically, it is not possible for us to build the app for every customer. So, there needs to be a way to fix this issue. Yes. there are several ways of course. When I googled, I could find 2 possible solutions.

1. Copy DLL.config file from DLL’s bin folder to EXE bin folder.

2. Merge the content of DLL.config file in EXE.config file.

The former approach is simple. But we should never forget it. The later approach is complex but a programmer can do it easily.

My deep thought is “why Microsoft forgot to think about this issue while upgrading VS versions?”, “Is this by design?”, “There could be many with similar issue. Is there no other way to automatically add DLL.config file in EXE folder.?”

Yes. There is a third workaround. Why not use Pre-Build events of your project? It’s quite simple and removes all the hassles. Here is the way to use it.

1. Open your EXE project properties & switch to “Build Events” tab

Pre Build Events - Properties Window

Pre Build Events - Properties Window

2. Write the below copy command in it.

copy $(SolutionDir)<>\bin\Debug\<>.dll.config   $(TargetDir)

3. Save it & Build the project. Viola.. you can now see your DLL.config file automatically included in your EXE bin folder. Now your customers can be advised to change the reference url in these config files on their own. Isn’t it simple & easy to do?

Enjoy !!!!.

Share This

Leave a Reply

Your email address will not be published. Required fields are marked *

9 − = three