简体   繁体   中英

Automatically copying dll.config to a referenced projects output directory

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 (eg 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 (ie 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

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.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM