将配置信息放入 DLL [英] Putting configuration information in a DLL

查看:19
本文介绍了将配置信息放入 DLL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的项目中,我拥有用作 Web 应用程序和控制台应用程序(从任务调度程序启动)的功能.为此,我将公共代码放在 Web 应用程序和控制台应用程序都使用的 DLL 中.这工作正常.

In my project I have functionality that is being used as a web application and as a console application (to be started from the task scheduler). To do that I put the common code in a DLL that is being used by both the web application and the console application. This works fine.

但是,控制台和 Web 应用程序现在具有大致相同的 App.config 和 Web.config.是否可以将此配置也放入 DLL 中并使其对两个应用程序都可用?

However, the console and web applications now have an App.config and Web.config that are mostly the same. Is it possible to put this configuration in the DLL as well and make it available to both applications?

推荐答案

是的,您可以并且应该将通用配置设置放在 DLL 的配置文件中.只需将 app.config 文件添加到 DLL 项目,并确保您从 DLL 内部读取配置设置.部署时,您的配置文件需要命名为MyDLL.dll.config"(假设您的 DLL 名为MyDLL.dll")并且与 DLL 位于同一文件夹中.

Yes, you can and should put the common configuration settings in the config file for your DLL. Just add an app.config file to the DLL project, and make sure you read the configuration settings from inside the DLL. When deployed, your config file needs to have the name "MyDLL.dll.config" (assuming your DLL is named "MyDLL.dll") and be in the same folder as the DLL.

这篇关于将配置信息放入 DLL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆