问题描述
我写了使用控制台应用程序的一些半自动化测试的测试平台,但我需要从我测试项目中的连接字符串。我不想直接或引用其他应用程序在我测试项目中的访问。
I am writing a test platform for some semi-automated testing using a Console application, but I need to get the connection string from the project I am testing. I don't want to reference the other application directly or otherwise have an accessor in the project I'm testing.
我已经设法到目前为止,要做的就是创建在我的TestUtility项目,其他项目的Web.config文件中的链接,我已经将它设置为复制如果新
。它在我的测试项目的根文件夹中唯一的Web.config,但 WebConfigurationManager.OpenWebConfiguration(空)
似乎是打开一些其他的Web.config文件,作为它的唯一的连接字符串是指.\SQLEXPRESS(而不是在我的解决方案的任何文件,我的道路将在此配置.\sql2008 - 而变化)。
What I've managed to do so far is create a link to the other project's Web.config file in my TestUtility project, and I've set it to Copy if newer
. It's the only Web.config in my test project's root folder, but WebConfigurationManager.OpenWebConfiguration(null)
seems to be opening some OTHER Web.config, as the only connection string in it refers to .\SQLEXPRESS (not in any file in my solution, my path would be .\sql2008 in this configuration - which varies).
任何提示或提示至于如何从另一个项目访问配置节?
Any hints or tips as to how to access that config section from another project?
(耶第一个问题)
推荐答案
总比不做好迟到:
var filePath = @"D:\PathToConfig\Web.config";
var map = new ExeConfigurationFileMap { ExeConfigFilename = filePath };
var configFile = ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.None);
我不能把这个信用,虽然,我发现它的>
这篇关于从另一个项目的Web.config访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!