title: .Net Standard 2.0 T4 Template Could not load file or assembly AutoMapper
body: <p>So I recently changed my projects from netcore2.0 to netstandard2.0 and am currently trying to get my T4 templates to work correctly. Presently I'm getting the following error:</p>
  
  <pre><code>Could not load file or assembly 'AutoMapper, Version=7.0.1, 
  Culture=neutral, PublicKeyToken=be96cd2c38ef1005' or one of its 
  dependencies. The system cannot find the file specified.
  </code></pre>
  
  <p>My project that contains the T4 template is referencing another project in my solution that has the AutoMapper v7.0.1 Nuget package installed, but the T4 template has no use for it, but it is using Reflection to get some type information from the referenced project:</p>
  
  <pre><code>&lt;#@ template debug="false" hostspecific="false" language="C#" #&gt;
  &lt;#@ assembly name="System.Core" #&gt;
  &lt;#@ import namespace="System.Linq" #&gt;
  &lt;#@ import namespace="System.Text" #&gt;
  &lt;#@ import namespace="System.Reflection" #&gt;
  &lt;#@ import namespace="Wanderift.Services.Resources.DataTransferObjects.Infrastructures" #&gt;
  &lt;#@ import namespace="System.Collections.Generic" #&gt; 
  &lt;#@ assembly name="$(TargetDir)Services.dll" #&gt;
  
  &lt;#@ output extension=".cs" #&gt;
  public class AdminDTO
  {
      &lt;#
      try
      {
          var editableObjs = Assembly
              .GetAssembly(typeof(GenericEditable&lt;&gt;))
              .GetTypes()
              .Where(p =&gt; p.BaseType != null &amp;&amp; p.BaseType.IsGenericType &amp;&amp; p.BaseType.GetGenericTypeDefinition() == (typeof(GenericEditable&lt;&gt;)))
              .ToList();
      }
      catch (Exception ex)
      {
          if (ex is System.Reflection.ReflectionTypeLoadException)
          {
              var typeLoadException = ex as ReflectionTypeLoadException;
              var loaderExceptions  = typeLoadException.LoaderExceptions;
          }
      }
      #&gt;
  }
  </code></pre>
  
  <p>The <code>GenericEditable&lt;&gt;</code> class is part of the <code>Services.dll</code> which should be referenced correctly from my T4 template.</p>
  
  <p>If I look in <code>.deps.json</code> file for the project containing the T4 Template I see that depends on Automapper:</p>
  
  <pre><code> "AutoMapper/7.0.1": {
      "dependencies": {
        "Microsoft.CSharp": "4.5.0",
        "System.ValueTuple": "4.5.0"
      },
      "runtime": {
        "lib/netstandard2.0/AutoMapper.dll": {}
      }
    },
  </code></pre>
  
  <p>I've uninstalled and reinstalled the AutoMapper Nuget package in my Services project, and it still runs perfectly fine, but the T4 template still throws the exception.</p>