title: Entity Framework Core Migration for ASP.Net Core Class Library
body: <p>I've been trying to follow the advice of Ben Cull (<a href="http://benjii.me/2016/06/entity-framework-core-migrations-for-class-library-projects" rel="nofollow noreferrer">http://benjii.me/2016/06/entity-framework-core-migrations-for-class-library-projects</a>), but the database is a little different in that I'm trying to inherit from ASP.NET Core IdentityUser class. I created a new solution containing the default ASP.NET Core Web Application from the VS2015 template (CodeFirstTest). I then added an ASP.NET Core class-library (CodeFirstTest.User) to the solution, which would be the data layer in the application and where I will also be setting up ASP.NET Core Identity.</p>
  
  <p>Following the advice of Ben Cull, I rewrote the CodeFirstTest.User project.json as follows.</p>
  
  <pre><code>{
    "version": "1.0.0-*",
  
    "buildOptions": {
      "emitEntryPoint": true
    },
    "frameworks": {
      "netcoreapp1.0": {
        "imports": [
          "dotnet5.6",
          "portable-net45+win8"
        ]
      }
    },
    "dependencies": {
      "Microsoft.NETCore.App": {
        "version": "1.0.1",
        "type": "platform"
      },
      "Microsoft.Extensions.Configuration": "1.0.1",
      "Microsoft.Extensions.Configuration.Json": "1.0.0",
      "Microsoft.AspNetCore.Identity.EntityFrameworkCore": "1.0.0",
      "Microsoft.EntityFrameworkCore.Design": "1.0.1",
      "Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final",
      "Microsoft.EntityFrameworkCore.SqlServer": "1.0.0"
    },
  
    "tools": {
      "Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final"
    }
  }
  </code></pre>
  
  <p>I also created a Program.cs file containing the entry point, and a User class that inherits from ASP.NET Core IdentityUser as shown below.</p>
  
  <pre><code>using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
  using Microsoft.EntityFrameworkCore;
  using Microsoft.EntityFrameworkCore.Infrastructure;
  
  namespace CodeFirstTest.User
  {
      public class Program
      {
          public static void Main(string[] args) { }
      }
  
      public class User : IdentityUser
      {
  
      }
  
      public class UserIdentityDbContext : IdentityDbContext&lt;User&gt;
      {
          public UserIdentityDbContext(DbContextOptions options)
          {
  
          }
      }
  
      public class TemporaryDbContextFactory : IDbContextFactory&lt;UserIdentityDbContext&gt;
      {
          public UserIdentityDbContext Create(DbContextFactoryOptions options)
          {
              var builder = new DbContextOptionsBuilder&lt;UserIdentityDbContext&gt;();
              builder.UseSqlServer("Server=(localdb)\\mssqllocaldb;Database=UserDb;Trusted_Connection=SqlTruncateException;MultipleActiveResultSets=true");
              return new UserIdentityDbContext(builder.Options);
          }
      }
  }
  </code></pre>
  
  <p>When I use the Project Manager Console to create the initial migration, I received the following errors.</p>
  
  <pre><code>PM&gt; Add-Migration -Name "Initial" -Project "CodeFirstTest.User"
  Could not invoke this command with the startup project 'CodeFirstTest'. Check that 'Microsoft.EntityFrameworkCore.Design' has been added to "dependencies" in the startup project and that the version of 'Microsoft.EntityFrameworkCore.Tools' in "tools" and 'Microsoft.EntityFrameworkCore.Design' are the same. See http://go.microsoft.com/fwlink/?LinkId=798221 for more details.
  PM&gt; Add-Migration -Name "Initial" -Project "CodeFirstTest.User"
  Unhandled Exception: System.MissingMethodException: Entry point not found in assembly 'Microsoft.EntityFrameworkCore.Design, Version=1.0.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.
  </code></pre>
  
  <p>I corrected the first error, but the second run will cause dotnet to fail with the 'Unhandled Exception' error.
  The question...
  Am I coding something incorrectly that prevents the migration from executing?</p>
  
  <p>Thank you.</p>