title: Load NuGet dependencies at runtime
body: <p>I'm looking for a way to run code by executing the following steps:</p>
  
  <ol>
  <li>Receiving a list of NuGet packages (a list of tuples ("package name", "package version", "path to main class").</li>
  <li>Retrieving them in a local directory (cf code sample #1)</li>
  <li>Loading them in my program at run-time</li>
  <li>Running the main classes by introspection (cf code sample #2)</li>
  </ol>
  
  <p>By now I am struggling with the third step. I can't find out how to load my package at run-time.</p>
  
  <p>My main question are:</p>
  
  <ul>
  <li>How can I find out in which folders were stored the retrieved packages?</li>
  <li>How can I load the content of those directories into my program?</li>
  </ul>
  
  <p><strong>Code Sample #1:</strong></p>
  
  <pre><code>private static void getPackageByNameAndVersion(string packageID, string version)
  {
      IPackageRepository repo =
              PackageRepositoryFactory.Default
                    .CreateRepository("https://packages.nuget.org/api/v2");
  
     string path = "C:/tmp_repo";
     PackageManager packageManager = new PackageManager(repo, path);
     Console.WriteLine("before dl pkg");
     packageManager.InstallPackage(packageID, SemanticVersion.Parse(version));
  
  }
  </code></pre>
  
  <p><strong>Code sample #2:</strong></p>
  
  <pre><code>private static void loadByAssemblyNameAndTypeName(string assemblyName, string typeName)
  {
     AppDomain isolationAppDomain = AppDomain.CreateDomain("tmp");
     object a = isolationAppDomain.CreateInstanceAndUnwrap(assemblyName, typeName);
     Type x = a.GetType();
     MethodInfo m = x.GetMethod("Main");
     m.Invoke(a, new object[] { });
  }
  </code></pre>