我正在尝试在自定义操作中安装我的产品期间更新 web.config 文件的自定义配置部分。我想使用实际的配置类来执行此操作,但是当安装程序运行时,它会加载我的安装程序类,但是 Configuration.GetSection 会在尝试从 Windows 系统目录加载我的自定义部分类时抛出 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>