title: AppSettings.json for Integration Test in ASP.NET Core
body: <p>I am following this <a href="https://docs.microsoft.com/en-us/aspnet/core/testing/integration-testing" rel="noreferrer">guide</a>. I have a <code>Startup</code> in the API project that uses an <code>appsettings.json</code> configuration file.</p>
  <pre><code>public class Startup
  {
      public Startup(IHostingEnvironment env)
      {
          var builder = new ConfigurationBuilder()
              .SetBasePath(env.ContentRootPath)
              .AddJsonFile(&quot;appsettings.json&quot;, optional: true, reloadOnChange: true)                
              .AddEnvironmentVariables();
          Configuration = builder.Build();
  
          Log.Logger = new LoggerConfiguration()
              .Enrich.FromLogContext()
              .ReadFrom.Configuration(Configuration)
              .CreateLogger();
      }
  </code></pre>
  <p>The particular part I'm looking at is the <code>env.ContentRootPath</code>. I did some digging around and it looks like my <code>appsettings.json</code> isn't actually copied to the <code>bin</code> folder but that is fine as <code>ContentRootPath</code> is returning <code>MySolution\src\MyProject.Api\</code>, which is where the <code>appsettings.json</code> file is located.</p>
  <p>So in my integration test project I have this test:</p>
  <pre><code>public class TestShould
  {
      private readonly TestServer _server;
      private readonly HttpClient _client;
  
      public TestShould()
      {
          _server = new TestServer(new WebHostBuilder().UseStartup&lt;Startup&gt;());
          _client = _server.CreateClient();
      }
  
      [Fact]
      public async Task ReturnSuccessful()
      {
          var response = await _client.GetAsync(&quot;/monitoring/test&quot;);
          response.EnsureSuccessStatusCode();
  
          var responseString = await response.Content.ReadAsStringAsync();
  
          Assert.Equal(&quot;Successful&quot;, responseString);
      }
  </code></pre>
  <p>This is basically copy and paste from the guide. When I debug this test, <code>ContentRootPath</code> is actually <code>MySolution\src\MyProject.IntegrationTests\bin\Debug\net461\</code>, which is obviously the build output folder for the test project and again the <code>appsettings.json</code> file is not there (yes I do have another <code>appsettings.json</code> file in the test project itself) so the test fails at creating the <code>TestServer</code>.</p>
  <p>I tried getting around this by modifying the test <code>project.json</code> file.</p>
  <pre><code>&quot;buildOptions&quot;: {
      &quot;emitEntryPoint&quot;: true,
      &quot;copyToOutput&quot;: {
          &quot;includeFiles&quot;: [
              &quot;appsettings.json&quot;
         ]
      }
  }
  </code></pre>
  <p>I hoped this would copy the <code>appsettings.json</code> file to the build output directory but it complains about the project missing a <code>Main</code> method for an entry point, treating the test project like a console project.</p>
  <p>What can I do to get around this? Am I doing something wrong?</p>