问题
Say I have 2 projects, where project A references project B. Project A is a web application project and project B is a class library.
The class library has an app.config file where some settings are stored. When I compile project A, projectB.dll is created in the bin folder.
What happens to the contents of the app.config file when the web application is deployed? Are the settings compiled into ProjectB.dll?
Is it possible to retrieve the contents of the app.config using a tool like reflector or ILSpy?
回答1:
You can add an app.config
to a library project, but it is not used or included in any of the output.
Configuration is meant to be done in the application - not in the library. So you need to put the configuration in question in the web.config of your web application, not in app.config of a library.
回答2:
At runtime, your project B will use the settings of your web application project (the host). So you would have to recopy your settings in the web.config file.
回答3:
App.config is configuration, not application - so it's not saved into dll and it can't be displayed by reflector or decompiled.
You have to configure Project B with settings for Project A (in web.config as it is web app).
There is no mechanism to automagicaly configure external modules, unless they have coded default fall-back values.
回答4:
App.config of your class library B becomes irrelevant. If you want to use data from there you should copy all the stuff to app.config of your parent application (in your case web.config). You will then be able to access contents of it using ConfigurationManager both from projects A and B
来源:https://stackoverflow.com/questions/8412116/what-happens-to-app-config-in-a-referenced-project