2011-01-25 10 views
3

VS2010のt4テンプレートからapp.configファイルのカスタムセクションにアクセスしようとしていますが、カスタムセクションを定義するアセンブリをロードできません。t4テンプレートのapp.configでカスタムセクションを使用する方法

ConfigurationAccessorを使用してセクション(ref http://skysanders.net/subtext/archive/2010/01/23/accessing-app.configweb.config-from-t4-template.aspx)を取得しています。

のapp.config:

MySection section = (MySection)config.Configuration.GetSection("MyProviders"); 

は、このエラーを与える:.ttファイルのこの行を呼び出す

<configSections> 
    <section name="MyProviders" type="System.Web.Security.MySection, MyAssembly" /> 
</configSections> 

<MyProviders default="SQLMyProvider"> 
    <providers> 
    <add name="SQLMyProvider" ... connectionStringName="MyConnectionString" /> 
    </providers> 
</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ファイル参照アセンブリとプロジェクトもそうですが、これはconfigセクションの読み込みには役立たないようです。 MySectionクラスをttコードブロックとして実装しようとしましたが、app.configでもそのクラスを使用することはできません。

アイデア?

+0

カスタムセクションの取得先はどこですか?私は別のappdomainsを使用して同じ問題があります。私の問題は、appdomainが正しくプローブできるように、私のセクションのdllをベースディレクトリに配置しなければならないということでした。 – michele

答えて

1

私はあなたがGACまたはちょうどそれを見つけることができるようにするためのビジュアル・スタジオPublicAssembliesフォルダにMyAssemblyを配置する必要があり

type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" 
0

<configSections>がフルアセンブリ名(バージョン、文化、なPublicKeyToken)が必要だと思います。後者の場所は<install_dir>\Common7\IDE\PublicAssembliesです。