title: Error: Build failed when dotnet ef migrations add InitialMigration
body: <p>I am trying to create a web API. Every time I run dotnet ef migrations add InitialMigration I get build failed error. I was following the youtube tutorial to build a dashboard using ASP.NET and Angular and Postgresql as databases. I tried looking up the docs, went through past StackOverflow queries and everything I could do still couldn't solve this issue. I am stuck in my project for 5 days just because of this issue.
  <a href="https://i.stack.imgur.com/qJmyn.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/qJmyn.png" alt="enter image description here" /></a></p>
  <p>.NET SDK 5.0</p>
  <p>Advantage.API.csproj</p>
  <pre><code>&lt;Project Sdk=&quot;Microsoft.NET.Sdk.Web&quot;&gt;
  
    &lt;PropertyGroup&gt;
      &lt;TargetFramework&gt;net5.0&lt;/TargetFramework&gt;
      &lt;UserSecretsId&gt;User-Secret-Id&lt;/UserSecretsId&gt;
    &lt;/PropertyGroup&gt;
  
    &lt;ItemGroup&gt;
    &lt;Folder Include=&quot;wwwroot\&quot; /&gt;
    &lt;/ItemGroup&gt;
  
    &lt;ItemGroup&gt;
      &lt;PackageReference Include=&quot;Microsoft.EntityFrameworkCore.Design&quot; Version=&quot;5.0.7&quot;&gt;
        &lt;IncludeAssets&gt;runtime; build; native; contentfiles; analyzers; buildtransitive&lt;/IncludeAssets&gt;
        &lt;PrivateAssets&gt;all&lt;/PrivateAssets&gt;
      &lt;/PackageReference&gt;
      &lt;PackageReference Include=&quot;Microsoft.EntityFrameworkCore.Tools&quot; Version=&quot;5.0.7&quot;&gt;
        &lt;IncludeAssets&gt;runtime; build; native; contentfiles; analyzers; buildtransitive&lt;/IncludeAssets&gt;
        &lt;PrivateAssets&gt;all&lt;/PrivateAssets&gt;
      &lt;/PackageReference&gt;
      &lt;PackageReference Include=&quot;Microsoft.EntityFrameworkCore.Tools.DotNet&quot; Version=&quot;2.0.3&quot; /&gt;
      &lt;PackageReference Include=&quot;Microsoft.Extensions.SecretManager.Tools&quot; Version=&quot;2.0.2&quot; /&gt;
      &lt;PackageReference Include=&quot;Microsoft.VisualStudio.Web.CodeGeneration.Tools&quot; Version=&quot;2.0.4&quot; /&gt;
      &lt;PackageReference Include=&quot;Npgsql.EntityFrameworkCore.PostgreSQL&quot; Version=&quot;5.0.6&quot; /&gt;
      &lt;PackageReference Include=&quot;Swashbuckle.AspNetCore&quot; Version=&quot;5.6.3&quot; /&gt;
    &lt;/ItemGroup&gt;
  
  &lt;/Project&gt;
  </code></pre>
  <p>ApiContext.cs</p>
  <pre><code>using Microsoft.EntityFrameworkCore;
  
  namespace Advantage.API.Demo.Models
  {
      public class ApiContext : DbContext
      {
          public ApiContext(DbContextOptions&lt;ApiContext&gt; options) : base(options) { }
  
          public DbSet&lt;Customer&gt; Customers { get; set; }
          public DbSet&lt;Order&gt; Orders { get; set; }
          public DbSet&lt;Server&gt; Servers { get; set; }
      }
  }
  </code></pre>
  <p>Program.cs</p>
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Threading.Tasks;
  using Microsoft.AspNetCore.Hosting;
  using Microsoft.Extensions.Configuration;
  using Microsoft.Extensions.Hosting;
  using Microsoft.Extensions.Logging;
  
  namespace Advantage.API
  {
      public class Program
      {
          public static void Main(string[] args)
          {
              CreateHostBuilder(args).Build().Run();
          }
  
          public static IHostBuilder CreateHostBuilder(string[] args) =&gt;
              Host.CreateDefaultBuilder(args)
                  .ConfigureWebHostDefaults(webBuilder =&gt;
                  {
                      webBuilder.UseStartup&lt;Startup&gt;();
                  });
      }
  }
  
  </code></pre>
  <p>Startup.cs</p>
  <pre><code>
  using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Threading.Tasks;
  using Microsoft.AspNetCore.Builder;
  using Microsoft.AspNetCore.Hosting;
  using Microsoft.AspNetCore.HttpsPolicy;
  using Microsoft.AspNetCore.Mvc;
  using Microsoft.Extensions.Configuration;
  using Microsoft.Extensions.DependencyInjection;
  using Microsoft.Extensions.Hosting;
  using Microsoft.Extensions.Logging;
  using Microsoft.EntityFrameworkCore;
  using Advantage.API.Models;
  
  
  namespace Advantage.API
  {
      public class Startup
      {
          private string _connectionString = null;
          public Startup(IConfiguration configuration)
          {
  
              Configuration = configuration;
          }
  
          public IConfiguration Configuration { get; }
  
          // This method gets called by the runtime. Use this method to add services to the container.
          public void ConfigureServices(IServiceCollection services)
          {
  
              _connectionString = Configuration[&quot;secretConnectionString&quot;];
              services.AddControllers();
              services.AddSwaggerGen(c =&gt;
              {
                  c.SwaggerDoc(&quot;v1&quot;, new OpenApiInfo { Title = &quot;Advantage.API&quot;, Version = &quot;v1&quot; });
              });
              services.AddEntityFrameworkNpgsql().AddDbContext&lt;ApiContext&gt;(opt=&gt;opt.UseNpgsql(_connectionString));
          }
  
          // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
          public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
          {
              if (env.IsDevelopment())
              {
                  app.UseDeveloperExceptionPage();
                  app.UseSwagger();
                  app.UseSwaggerUI(c =&gt; c.SwaggerEndpoint(&quot;/swagger/v1/swagger.json&quot;, &quot;Advantage.API v1&quot;));
              }
  
              app.UseHttpsRedirection();
  
              app.UseRouting();
  
              app.UseAuthorization();
  
              app.UseEndpoints(endpoints =&gt;
              {
                  endpoints.MapControllers();
              });
          }
      }
  }
  
  </code></pre>
  <p><a href="https://i.stack.imgur.com/Z5UK0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Z5UK0.png" alt="enter image description here" /></a></p>