title: T4 template and Assembly.Load
body: <p>This is my first question on StackOverflow so Hi :)</p>
  
  <p>Is it possible to load assembly by Assembly name using Assembly.Load() in t4 template? 
  I would like to use it to get all types with ServiceContract attribute in loaded assembly.</p>
  
  <pre><code>    var loadedAssembly = Assembly.Load(assemblyName);
      var types = from type in loadedAssembly.GetTypes()
      where Attribute.IsDefined(type, typeof(ServiceContractAttribute))select type;
  </code></pre>
  
  <p>Desired Assembly is referenced in project where my template is. I figured out that </p>
  
  <pre><code>    &lt;#@ assembly name="$(TargetDir)\DesiredAssemblyName.dll" #&gt;
      var loadedAssembly = Assembly.GetAssembly(typeof(SomeType));
  </code></pre>
  
  <p>works but it does not seems like good solution. Besides I want that template to transform after build and when I add following lines to .csproj</p>
  
  <pre class="lang-xml prettyprint-override"><code>      &lt;Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\
           TextTemplating\v10.0\Microsoft.TextTemplating.targets"/&gt;
        &lt;PropertyGroup&gt;
           &lt;TransformOnBuild&gt;true&lt;/TransformOnBuild&gt;
        &lt;/PropertyGroup&gt;
        &lt;ItemGroup&gt;
           &lt;!--Add VS\...\PublicAssemblies to the list of places
           to look for assemblies used by templates.--&gt; 
           &lt;T4ReferencePath Include="..\Onii.Vespa.AppServer\"/&gt;
        &lt;/ItemGroup&gt;
  </code></pre>
  
  <p>solution with Assembly.GetAssembly does not work either.
  Thank you for all suggestions.</p>