title: How to create migrations from library project by targeting a Web Api project and use the lib project as the migrations assembly?
body: <p>I created a .Net 5 Web Api project and a library project. In the library project I created a database entity, a context and an extension to register the context on startup</p>
  <pre><code>public static IServiceCollection AddContexts(this IServiceCollection services)
      =&gt; services.AddDbContext&lt;CarsContext&gt;(x =&gt; x.UseNpgsql(&quot;Host=host;Database=db;Username=user;Password=pw&quot;));
  </code></pre>
  <p>In the Web Api project I call the <code>AddContexts</code> method in the startup file. With the EF cli I want to generate migrations in the lib project by calling this in the Api directory</p>
  <pre><code>dotnet ef migrations add Init --startup-project . -o ./LibProj
  </code></pre>
  <p>The build succeeds but unfortunately I get this error</p>
  <blockquote>
  <p>Your target project 'ApiProj' doesn't match your migrations assembly
  'LibProj'. Either change your target project or change your migrations
  assembly. Change your migrations assembly by using
  DbContextOptionsBuilder. E.g. options.UseSqlServer(connection, b =&gt;
  b.MigrationsAssembly(&quot;ApiProj&quot;)). By default, the migrations assembly
  is the assembly containing the DbContext. Change your target project
  to the migrations project by using the Package Manager Console's
  Default project drop-down list, or by executing &quot;dotnet ef&quot; from the
  directory containing the migrations project.</p>
  </blockquote>
  <p>I don't think my Api project should deal with database related things. Is there a way I can fix my command to use the Api project as the startup project but take the context from the lib project and put the migrations into the lib project?</p>