title: .net core 3.1 Console App The configuration file 'appsettings.json' was not found
body: <p>When running a console app outside of a local environment, .net core 3.1 is looking for the appsettings.json file in a different directory than where the program executes.</p>
  <ul>
  <li>The configuration file 'appsettings.json' was not found and is not optional. The physical path is 'C:\windows\system32\appsettings.json'.</li>
  </ul>
  <p>In previous versions of dotnet using the Environment.CurrentDirectory or Directory.GetCurrentDirectory() but not working in 3.1. How do you change this so that it looks in the directory where it is running? The below does not work</p>
  <pre><code>        using var host = Host.CreateDefaultBuilder()
              .ConfigureHostConfiguration(builder =&gt;
              {
                  builder.SetBasePath(Environment.CurrentDirectory);                    
                  builder.AddCommandLine(args);
              })
              .UseConsoleLifetime(options =&gt; options.SuppressStatusMessages = true)
              .UseServiceProviderFactory(new AutofacServiceProviderFactory())
              .ConfigureAppConfiguration((hostContext, builder) =&gt;
              {
                  builder.AddJsonFile(&quot;appsettings.json&quot;);
                  hostContext.HostingEnvironment.EnvironmentName = Environment.GetEnvironmentVariable(&quot;NETCORE_ENVIRONMENT&quot;);
                  if (hostContext.HostingEnvironment.EnvironmentName == Environments.Development)
                  {
                      builder.AddJsonFile($&quot;appsettings.{hostContext.HostingEnvironment.EnvironmentName}.json&quot;, optional: true);
                      builder.AddUserSecrets&lt;Program&gt;();
                  }
              })
  </code></pre>