Jim Culverwell
Jim Culverwell

Reputation: 2813

Referencing .Net framework dll which needs to read configuration data

I have created an Asp.net Core (.Net framework) website which references a .Net framework dll. The dll needs to read configuration data from the calling applications web.config or application.config file.

How can I do this in an Asp.net Core application? I have tried adding the configuration settings to the web.config in the ASP.Net Core application but they are not being picked up in the dll.

Upvotes: 1

Views: 518

Answers (1)

Jim Culverwell
Jim Culverwell

Reputation: 2813

After a bit more research I noticed that although the Asp.Net Core (.Net Framework) project uses appsettings.json for settings it still contains a web.config file. So I added the settings the Dll needs into the web.config and then added the 'copyToOutput' setting (below) to the project.json file.

"buildOptions": { "emitEntryPoint": true, "preserveCompilationContext": true, "copyToOutput": "web.config" },

Now the Dll can retrieve the settings it needs. One downside to this that you may end up doubling up some configuration settings (adding them to appsettings.json and web.config) if both your Asp.Net Core and Dll require them. I also haven't tested deploying to Azure etc.

Welcome any comments.

Upvotes: 1

Related Questions