我正在尝试在我的设置和部署项目中调用自定义操作来更新我的应用程序中 app.config 中的某些项目。我以通常的方式结束了自定义配置部分,例如:
[ConfigurationProperty("serviceProvider", IsRequired = true)]
public string ServiceProvider
{
get { return (string)base["serviceProvider"]; }
set { base["dataProviderFactory"] = value; }
}
我已经设置了要在安装的安装部分中调用的自定义操作,就在 base.Install(stateSaver) 之后。代码是:
string exePath = string.Format("{0} MyApp.exe", Context.Parameters["DP_TargetDir"]);
SysConfig.Configuration config = ConfigurationManager.OpenExeConfiguration(exePath);
Configuration. MyApp section = Configuration.MyApp)config.GetSection("MyApp");
当我运行这个时,我得到这个错误:
System.Configuration.ConfigurationErrorsException:为 MyApp 创建配置节处理程序时出错:无法加载文件或程序集“MyCompany。MyApp.Configuration' 或其依赖项之一。该系统找不到指定的文件。(C:\Program Files\MyCompany\MyApp\MyApp.exe.config 第 5 行)---> System.IO.FileNotFoundException:无法加载文件或程序集“MyCompany.MyApp.Configuration”或其依赖项之一。该系统找不到指定的文件。
配置中的第 5 行是:
<section name="MyApp"
type="MyCompany.MyApp.Configuration.MyApp, MyCompany.MyApp.Configuration"
requirePermission="false" />
带有安装程序代码的类库(这是该库中唯一的类)具有对配置程序集的引用。
我在这里遗漏了一些非常明显的东西吗?我无法弄清楚为什么找不到配置的引用。
任何帮助/建议将不胜感激。