1

I used the method suggested in the following post to include an App.config file to Class Library project.

Equivalent to 'app.config' for a library (DLL)

It works as mentioned and creates the .dll.config file in respective Class Library projects output directory (e.g. ApiCommunicator\bin\Debug).

I have referenced this Class Library project as a "Project Reference" from another Console Application project within the same Visual Studio solution.

Now the problem is, the .dll is getting copied to the Console Projects output directory (i.e. Engine\bin\Debug) but the .dll.config doesn't. If I manually copy it, everything works fine but is there a way to configure Visual Studio to auto copy .dll.config to any other project's output directory which references the Class Library project?

Thanks, Bathiya

Community
  • 1
  • 1
Bathiya Priyadarshana
  • 1,325
  • 6
  • 22
  • 35

3 Answers3

3

Although I am late, but my answer can help others. I used the following command as pre-build event:

copy /Y $(SolutionDir)\[YOUR_LIBRARY_PROJECT]\app.config $(ProjectDir)$(OutputPath)[YOUR_LIBRARY_NAME].dll.config

I tried to be dynamic as much as possible, and the above command worked.

I posted the same answer at the question Can we autocopy the *.dll.config? as well.

Community
  • 1
  • 1
Nadeem Jamali
  • 1,353
  • 3
  • 16
  • 27
  • 1
    I needed to add quotes (") around the paths and your example worked. –  Jan 10 '17 at 16:59
0

It would have to be the other way around: Projects referencing your dll could copy it's dll.config from a known location as a post-build event.

However I think it would be much better to provide the configuration from within the consumer application's configuration. That way each referencing project would have an option to adjust the configuration to its needs, which I would think is a critical feature.

If that is not the case, then I don't see the reason for having the .dll.config, and you can just hardcode the values.

snaits
  • 330
  • 1
  • 3
  • 9
  • Even if the configuration isn't dependent on referencing projects, there are reasons against hardcoding its values. Changing settings saved in a dll.config would not require a rebuild for one. Another reason would be to allow multiple possible configurations when using different dll.config files. – drouning Feb 09 '18 at 10:00
0

You can use the 'Build Events' tab of your project properties to run command line instructions post-build or even pre-build. This way, you can use a simple

copy /Y "<yourconfigfilepath>" "<yourprojectfilepath>\Engine\bin\Debug\"

This will copy the dll.config file you are needing over to the correct directory.

Lex Webb
  • 2,772
  • 2
  • 21
  • 36