.NET 类库项目中的多个 App.Config 文件 [英] Multiple App.Config Files in .NET Class library project

查看:30
本文介绍了.NET 类库项目中的多个 App.Config 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个类库项目.现在默认情况下,我有一个 App.Config 文件,以便我将所有特定于环境的数据放入该 Config 文件中.

I am creating one class library project. Now by default I have one App.Config file so that I am putting all environment specific data in that Config file.

现在基于环境(无论是开发/测试/生产),我计划在 VS 2010 中拥有三个 App.Config 文件,例如

Now based on the Environment (whether Dev / Test / Production), I am planning to have three App.Config files in VS 2010 such as

App.Dev.Config

App.Test.Config

App.Prod.Config

想知道应用程序如何知道要使用哪个配置文件.

Wondering how would the application know which config file to use.

任何人都实现了这个场景.任何代码示例/文章都会有所帮助.

Anyone implemented this scenario. Any Code samples / Articles would be helpful.

谢谢

推荐答案

该应用程序将使用名为 YourExcecutable.exe.config 的配置文件,默认情况下该文件是包含在您的(可执行)项目中的 App.config 文件.请注意,.NET 仅为整个应用程序加载一个配置文件.您不能在不编码的情况下使用多个配置文件(即每个库项目一个).

The app will use the config file named YourExcecutable.exe.config which is by default the file App.config included in your (executable) project. Note, that .NET only loads one config file for the whole application. You cannot use multiple configuration files (i.e. one per library project) without coding.

  1. 选项:您可以使用构建后事件和不同的解决方案配置将一个或另一个 App.Config 文件复制到输出文件夹

  1. Option: You can use postbuild events and different solution configurations to copy one or another App.Config file to the output folder

选项:您可以使用 ConfigurationManager 类通过代码加载备用配置文件.

Option: You can use the ConfigurationManager Class to load an alternate config file by code.

这篇关于.NET 类库项目中的多个 App.Config 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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