我正在尝试在自定义操作中安装产品期间更新web.config文件的自定义配置节。但是,我想使用实际的配置类来执行此操作,但安装程序在运行它时会加载我的安装程序类,但随后会尝试从Windows系统目录加载我的自定义节类,因此Configuration.GetSection会抛出File Not Found异常。我设法通过将所需的程序集复制到Windows系统目录中来实现此目的,但这不是一个理想的解决方案,因为我无法保证我总能访问该目录。在安装程序类中编辑自定义配置节
我该怎么解决这个问题?
我更新的代码如下所示
[RunInstaller(true)]
public partial class ProjectInstaller : Installer
{
public override void Install(System.Collections.IDictionary stateSaver)
{
//some code here
webConfig = WebConfigurationManager.OpenWebConfiguration("MyService");
MyCustomSection mySection = webconfig.GetSection("MyCustomSection") //<--File Not Found: CustomConfigSections.dll
//Update config section and save config
}
}
我的配置文件看起来像这样
<configuration>
<configSections>
<section name="myCustomSection" type="CustomConfigSections.MyCustomSection, CustomConfigSections" />
</configSections>
<myCustomSection>
<!-- some config here -->
</myCustomSection>
</configuration>
你解决了吗?我有同样的问题。我可以访问AppSettings,但是加载ConfigHandler所需的DLL是安装的一部分,虽然看起来存在于文件夹中,但无法访问。 我认为这可能有帮助,但目前为止没有运气: AppDomain currentDomain = AppDomain.CurrentDomain; currentDomain.AssemblyResolve + = new ResolveEventHandler(MyResolveEventHandler); – Junto 2010-03-04 13:32:54
我确实找到了另一个更好的解决方案。您可以使用Orca编辑msi来更改其执行的顺序,以便在自定义操作运行之前部署程序集并将其放入GAC中。仍然不理想,但比以前更好。 – 2010-03-05 09:52:38