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

查看:459
本文介绍了.NET Config文件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"/>

但是失败并出现错误:


configSource属性无效:configSource'D:\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并从外部位置获取值?

我很高兴有必要添加代码来做到这一点,但我不想替换整个配置管理器系统。 / p>

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 Config文件configSource在应用程序目录文件夹之外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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