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

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

问题描述

我创建一个类库项目。 现在,在默认情况下我有一个app.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中3的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.

任何人都实现了这个场景。任何code样品/文章将是有益的。

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. 选项:您可以使用postbuild事件和不同的解决方案配置,以复制一个或另一个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的类装载由code备用配置文件

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

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

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