简体   繁体   English

将一个app.config文件用于多个项目

[英]Using one app.config file for multiple projects

I have a solution with the following setup: 我有以下设置的解决方案:

X amount of class library projects Y amount of console application projects X个类库项目的数量Y控制台应用程序项目的数量

Each of these projects may have 0 or more configuration parameters. 这些项目中的每个项目都可以具有0个或更多配置参数。

Now, I'd like to have only one App.config for user to specify settings and that App.config will only contain parameters of all the reference projects of the console application project to be run. 现在,我只希望有一个App.config供用户指定设置,并且该App.config将仅包含要运行的控制台应用程序项目的所有参考项目的参数。

I've tried giving each project a Settings file and then linking them to the console applications according to their dependencies but that didn't work. 我尝试为每个项目设置一个设置文件,然后根据它们的依赖关系将它们链接到控制台应用程序,但这没有用。

I've also tried just lumping all the configurations together in one class library project and have each console application link to that app.config (or settings file). 我还尝试将所有配置集中在一起放在一个类库项目中,并使每个控制台应用程序链接到该app.config(或设置文件)。 But that also didn't work (ie changes of the app.config or the settings file in the class library will not update the .config of the executable) 但这也不起作用(即更改app.config或类库中的设置文件不会更新可执行文件的.config)

Is what I am trying to do possible? 我想做的事可能吗?

Yes, it is possible. 对的,这是可能的。 You just need to open the app file. 您只需要打开应用文件。 Follow the next example: 遵循下一个示例:

ConfigurationManager.OpenExeConfiguration("C:\Test\SomeProject.dll");
XmlNode loggingConfigNode = ConfigurationManager.GetSection("log4net") as XmlNode;

I guess that you will have to open each setting file in order to use the settings, or you will have to consolidate all the settings in a single app.config and then your applications can access the file by open it. 我想您必须打开每个设置文件才能使用设置,或者必须将所有设置合并到一个app.config中,然后您的应用程序才能通过打开文件来访问文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM