我正在嘗試在自定義操作中安裝產品期間更新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