.NET配置文件configSource应用程序目录文件夹之外 [英] .NET Config Files configSource outside the application directory folder

查看:316
本文介绍了.NET配置文件configSource应用程序目录文件夹之外的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个应用程序一个控制台应用程序,另一个是ASP.NET应用程序。他们都需要知道同样的appSettings和的ConnectionStrings。因此,理想情况下,我想用的app.config / web.config文件中的configSource属性指向了一个中心位置。例如

I have two applications one a console application and the other an ASP.NET app. They both need to know the same appSettings and connectionStrings. So ideally I would like to use the configSource property of app.config/web.config files to point that to a central location. For example

<connectionStrings configSource="D:\connectionStrings.config"/>
<appSettings configSource="D:\appSettings.config"/>

这不过失败,出现错误:

That however fails with an error:

的configSource属性无效:该configSourceD:\ appSettings.config'是无效的。它必须引用文件在同一目录或子目录中的配置文件。

The configSource attribute is invalid.: The configSource 'D:\appSettings.config' is invalid. It must refer to a file in the same directory or in a subdirectory as the configuration file.

反正是有还是使用配置管理器的appSettings /的ConnectionStrings和从外部位置获取值?
我很高兴有加code做到这一点,但我不希望有更换整个配置管理系统。

Is there anyway to still use the configuration managers appSettings/connectionStrings and get the values from an external location?
I'm happy with having to add code to do it, but I don't want to have to replace the entire configuration manager system.

推荐答案

另一种解决方案是简单地在配置文件中所有的项目为纽带,而不是实际拷贝文件到您的项目中添加。然后设置建设行动的文件,以内容和复制到输出目录,以复制,如果新,当你编译项目,你会在输出目录中的文件。

Another solution is simply to add the configuration file in all your projects as a link instead of actually copying the file to your projects. Then set the "Build Action" of the file to "Content" and "Copy to Output Directory" to "Copy if newer" and when you compile the project you will have the file in the output directory.

要添加为纽带,选择添加为链接中的添加现有项文件对话框。

To add the file as a link choose "Add as link" in the "Add Existing Item" dialog.

这篇关于.NET配置文件configSource应用程序目录文件夹之外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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