【发布时间】:2011-02-01 08:13:58
【问题描述】:
我的猜测是这个问题将属于“duh”的范畴,但是,我很困惑。
在例如 Windows 窗体应用程序中使用配置文件时,可以在 C:\Program files\CompanyName\ProductName\Application.exe.config 中找到配置文件。但是,对于我正在开发的类库,在从 Visual Studio 安装它(与另一个项目串联)后,我在安装文件夹中看不到“ClassLibrary.dll.config”文件。即使我在任何地方都看不到该文件,但从中检索数据也可以正常工作。另外,从类库中的方法运行以下代码会返回您期望的路径:C:\Program files\CompanyName\ProductName\ClassLibrary.dll.config。
如果有人能阐明我在这里所缺少的东西,那真是太棒了。
public static string MyMethod()
{
Assembly assem = Assembly.GetExecutingAssembly();
Configuration config = ConfigurationManager.OpenExeConfiguration(assem.Location);
return "The assembly location was: " + assem.Location + Environment.NewLine +
"The config file path was: " + config.FilePath;
// Gives me "C:\Program files\CompanyName\ProductName\ClassLibrary.dll.config"
}
【问题讨论】:
标签: c# app-config class-library