我试图完成这个异常处理程序:如何找到活动的app.config文件的路径?
if (ConfigurationManager.ConnectionStrings["ConnectionString"]==null)
{
string pathOfActiveConfigFile = ...?
throw new ConfigurationErrorsException(
"You either forgot to set the connection string, or " +
"you're using a unit test framework that looks for "+
"the config file in strange places, update this file : "
+ pathOfActiveConfigFile);
}
这个问题似乎当我使用NUnit只发生在我身上。
这比使用Assembly.GetEntryAssembly()+“.config”更好,这在ASP.NET的某些情况下不起作用,并且在某些情况下在使用AppDomains时不起作用。 – Contango 2013-10-08 13:27:22
我该如何改变这条道路? – 2015-05-06 13:59:18
谢谢。我有一个项目从VS2008升级 - > VS2013拒绝读取app.config文件。然后,我通过AppDomain.CurrentDomain.SetupInformation.ConfigurationFile了解到它正在搜索未生成的XXX.vshost.exe.config。所以我把它关闭VS主机在项目属性调试选项卡。然后,我不得不将我的app.config文件重命名为{projectName} .config,并将其放入bin文件夹,并最终生效 – drzounds 2016-06-29 19:50:07