在 Visual Studio 中组合多个配置文件 [英] Combining multiple config files in Visual Studio

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

问题描述

我在 Visual Studio 2008 中有一个解决方案,其中包含多个 C# 项目.每个项目都有自己的配置文件(App.config 和 Settings.settings).这在架构上是有意义的,因为每个模块都是自治的,并用于许多不同的解决方案.

I have a solution in Visual Studio 2008 which contains multiple C# projects. Each project has it's own config file (App.config and Settings.settings). This makes sense architecturally as each module is autonomous and is used in a number of different solutions.

我的问题是,当我编译解决方案时,只包含启动项目(或包含可执行文件的项目)的配置文件.对于其他模块,配置设置被编译到 DLL 中.所以我的问题是,在 Visual Studio 中是否有任何方法可以组合多个配置文件或链接它们以便可以在运行时更改 DLL 的设置?

My problem is that when I compile the solution only the config file for the startup project (or project containing the executable) is included. For other modules the config settings are compiled into the DLL. So my question is, is there any way in Visual Studio of combining multiple config files, or linking them so that settings for DLLs can be changed at runtime?

推荐答案

我不确定这是否是您正在寻找的内容,或者它是否会有所帮助,但作为进入探索领域的引导,请注意,您可以链接两个配置文件.例如,我在一个单独的文件中有我的连接字符串,所以我在 Web.config 中的 connectionStrings 行读取:

I'm not sure if this is what you are looking for or if it will help but just as a lead into an area to explore, note that you can link two Config files. For example, I have my connection string in a separate file so my connectionStrings line in Web.config reads:

<connectionStrings configSource="WebCS.config"/>

然后,在单独的文件中,我有:

Then, in the separate file, I have:

<connectionStrings>
    <add name="BSDIConnString" 
         connectionString="Data Source=XXX;Initial Catalog=XXX;User ID=XXX;Password=XXX" 
         providerName="System.Data.SqlClient"/>
</connectionStrings>

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

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