我想從VS2010中的t4模板訪問app.config文件中的自定義部分,但無法加載定義自定義部分的程序集。如何使用t4模板中的app.config中的自定義部分
我使用ConfigurationAccessor獲取該部分(編號http://skysanders.net/subtext/archive/2010/01/23/accessing-app.configweb.config-from-t4-template.aspx)。
的app.config:
<configSections>
<section name="MyProviders" type="System.Web.Security.MySection, MyAssembly" />
</configSections>
<MyProviders default="SQLMyProvider">
<providers>
<add name="SQLMyProvider" ... connectionStringName="MyConnectionString" />
</providers>
</MyProviders>
調用在.TT文件這一行:
MySection section = (MySection)config.Configuration.GetSection("MyProviders");
給出了這樣的錯誤:
Running transformation: System.Configuration.ConfigurationErrorsException: An error occurred creating the configuration section handler for MyProviders: Could not load file or assembly 'MyAssembly' or one of its dependencies. The system cannot find the file specified.
的.TT文件引用的組裝和項目也是如此,但這似乎並不能幫助加載配置部分。 我曾嘗試將MySection類實現爲tt代碼塊,但無法在app.config中使用該類。
任何想法?
您嘗試檢索自定義區域的位置?我使用不同的應用程序域也遇到同樣的問題。我的問題是,我的部分DLL必須放在基本目錄,所以appdomain可以正確探測。 – michele 2011-01-25 10:44:41