C#中的多个配置文件 [英] multiple config file in c#

查看:566
本文介绍了C#中的多个配置文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含1个控制台应用程序和2个库的解决方案.

I have a solution containing 1 console application and 2 libraries.

在库中,我有两个不同的app.configs作为示例,我的data.config

In the libraries I have two different app.configs for an example my data.config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings>
    <add key="OutputFileFolder" value="c:\\log" />
    <add key="OutputIndexFile" value="c:\\log\index.xml" />
  </appSettings>
</configuration>

在这个库类中,我在构造函数中

And in this library class I have in the constructor

_indexPath = ConfigurationManager.AppSettings["OutputIndexFile"]; 

但是我应该如何从主控制台应用程序中加载Data.config文件(这应该是主配置文件)?

But how should I load the Data.config file from my main console application (this should be the main config file)?

推荐答案

配置文件在运行时不相关.控制台应用程序项目中的配置文件(如果有)将被使用.

Config files in your dll projects are not relevant at runtime. The config file (if any) in your console application project is the one that will get used.

如果要在两个单独的项目中使用配置文件,可以将其添加构建后事件将其复制过来.但是,这两者似乎都有些古怪.

If you want to use a configuration file in two separate projects, you can add it as a link to your second project, or you could use a post-build event to copy it over. However both of these seem a little hacky.

这篇关于C#中的多个配置文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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