title: .NET Core 2.0 WebAPI with MySQL DB - dotnet publish -- Connection string null when running .dll
body: <p>Looking for some insight into this issue. To me, it looks like all the configuration aligns with what is expected, but whenever i try to run <code>dotnet publish TestAPI.dll</code> and attempt to hit an endpoint, I see the following:</p>
  
  <blockquote>
    <p>ArgumentNullException: Value cannot be null. Parameter name:
    connectionString
    Microsoft.EntityFrameworkCore.Utilities.Check.NotEmpty(string value,
    string parameterName)
    Microsoft.EntityFrameworkCore.Infrastructure.RelationalOptionsExtension.WithConnectionString(string
    connectionString)
    Microsoft.EntityFrameworkCore.MySQLDbContextOptionsExtensions.UseMySQL(DbContextOptionsBuilder
    optionsBuilder, string connectionString,
    Action MySQLOptionsAction)
    TestAPI.Startup.b__4_0(DbContextOptionsBuilder
    options) in Startup.cs
    +
                                                        options.UseMySQL(Configuration.GetConnectionString("DefaultConnection")));
    Microsoft.Extensions.DependencyInjection.EntityFrameworkServiceCollectionExtensions+&lt;>c__DisplayClass0_0.b__0(IServiceProvider
    p, DbContextOptionsBuilder b)
    Microsoft.Extensions.DependencyInjection.EntityFrameworkServiceCollectionExtensions.DbContextOptionsFactory(IServiceProvider
    applicationServiceProvider, Action optionsAction)
    Microsoft.Extensions.DependencyInjection.EntityFrameworkServiceCollectionExtensions+&lt;>c__DisplayClass5_0.b__0(IServiceProvider
    p)
    Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitFactory(FactoryCallSite
    factoryCallSite, ServiceProvider provider)
    Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor.VisitCallSite(IServiceCallSite
    callSite, TArgument argument)</p>
  </blockquote>
  
  <p>I can confirm that it's working as expected when I run the application from the IDE (Visual Studio for Mac). Here's my relevant config:</p>
  
  <p><strong>appsettings.json</strong></p>
  
  <pre><code>{
    "ConnectionStrings": {
      "DefaultConnection": "server=localhost;userid=root;pwd=root;port=3306;database=Expenses;sslmode=none;"
    },
    "Logging": {
      "IncludeScopes": false,
      "Debug": {
        "LogLevel": {
          "Default": "Warning"
        }
      },
      //"Console": {
      //  "LogLevel": {
      //    "Default": "Warning"
      //  }
      //}
    }
  }
  </code></pre>
  
  <p><strong>appsettings.Development.json</strong></p>
  
  <pre><code>{
    "ConnectionStrings": {
      "DefaultConnection": "server=localhost;userid=root;pwd=root;port=3306;database=Expenses;sslmode=none;"
    },
    "Logging": {
      "IncludeScopes": false,
      "LogLevel": {
        "Default": "Debug",
        "System": "Information",
        "Microsoft": "Information"
      }
    }
  }
  </code></pre>
  
  <p><strong>Startup.cs</strong></p>
  
  <pre><code>using Microsoft.AspNetCore.Builder;
  using Microsoft.AspNetCore.Hosting;
  using Microsoft.EntityFrameworkCore;
  using Microsoft.Extensions.Configuration;
  using Microsoft.Extensions.DependencyInjection;
  using TestAPI.Data;
  using TestAPI.Data.Models;
  using System;
  using Microsoft.Extensions.Logging;
  
  namespace TestAPI
  {
      public class Startup
      {
          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)
          {
              services.AddCors();
  
              services.AddMvc();
  
              services.AddDbContext&lt;ExpensesDbContext&gt;(options =&gt;
                                                      options.UseMySQL(Configuration.GetConnectionString("DefaultConnection")));
              services.AddTransient&lt;IBaseDa&lt;Accounts&gt;, AccountsDataAccess&gt;();
              services.AddTransient&lt;IExpensesDa, ExpensesDa&gt;();
          }
  
          // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
          public void Configure(IApplicationBuilder app, IHostingEnvironment env)
          {
              env.EnvironmentName = "Development";
  
              if (env.IsDevelopment())
              {
                  app.UseDeveloperExceptionPage();
              }
  
              app.UseCors(builder =&gt; builder
                  .AllowAnyOrigin()
                  .AllowAnyMethod()
                  .AllowAnyHeader()
                  .AllowCredentials());
  
              app.UseMvc();
          }
      }
  }
  </code></pre>
  
  <p><strong>Program.cs</strong></p>
  
  <pre><code>using Microsoft.AspNetCore;
  using Microsoft.AspNetCore.Hosting;
  
  namespace TestAPI
  {
      public class Program
      {
          public static void Main(string[] args)
          {
              //var builder = new ContainerBuilder();
  
              //// register types here for DI
              //builder.RegisterType&lt;AccountsDataAccess&gt;().As&lt;IBaseDa&lt;Accounts&gt;&gt;();
  
              //_container = builder.Build();
  
              BuildWebHost(args).Run();
          }
  
          public static IWebHost BuildWebHost(string[] args) =&gt;
              WebHost.CreateDefaultBuilder(args)
                  .UseStartup&lt;Startup&gt;()
                  .Build();
      }
  }
  </code></pre>
  
  <p>even tried editing the appsettings.Development.json and appsettings.json within the corresponding publish folder (e.g. bin/Release/netcoreapp2.0/publish)</p>
  
  <p>Any help is greatly appreciated! Thanks all</p>