title: Single File ASP.NET Core 5 web app does not load static resources
body: <p>I'm trying to create a single file asp.net core 5 web app. Goal is to have a single .exe file, run the Kestrel server by executing this exe file and load the page in the browser.</p>
  <p>I created an ASP.NET Core 5 template app in VS 2019. Then using cli I run this command:</p>
  <pre><code>dotnet publish -c Release -r win-x64 /p:PublishSingleFile=true \n 
  /p:IncludeNativeLibrariesForSelfExtract=true --self-contained true
  </code></pre>
  <p>This generates an exe file, which when I copy elsewhere, runs without a problem.
  But when I browse the page, none of the static files are loaded:</p>
  <p><a href="https://i.stack.imgur.com/dhW3E.png" rel="noreferrer"><img src="https://i.stack.imgur.com/dhW3E.png" alt="enter image description here" /></a></p>
  <p>What would be the proper way of generating a single file asp.net core app, so it loads static content ?</p>
  <p><strong>EDIT</strong></p>
  <p>As requested, putting here the screenshot of the output after the publish</p>
  <p><a href="https://i.stack.imgur.com/9WtO5.png" rel="noreferrer"><img src="https://i.stack.imgur.com/9WtO5.png" alt="enter image description here" /></a></p>
  <p><strong>EDIT 2</strong></p>
  <p>To get a reproducible project:</p>
  <p>Visual Studio 2019 -&gt; New Solution -&gt; ASP.NET Core Web App with the configuration below</p>
  <p><a href="https://i.stack.imgur.com/k4yeH.png" rel="noreferrer"><img src="https://i.stack.imgur.com/k4yeH.png" alt="enter image description here" /></a></p>
  <p><strong>EDIT 3</strong></p>
  <p>Thanks to the answer by @JHBonarius, I changed the Program.cs to set <code>ContentRoot</code> to a temp folder where <code>wwwroot</code> content is getting extracted.</p>
  <pre><code>public class Program
      {
          public static void Main(string[] args)
          {
              var path = Path.Combine(Path.GetTempPath(), &quot;.net&quot;, typeof(Program).Assembly.GetName().Name);
  
              var directory = 
                  Directory
                      .GetDirectories(path)
                      .Select(path =&gt; new DirectoryInfo(path))
                      .OrderByDescending(di =&gt; di.LastWriteTime)
                      .First();
  
              CreateHostBuilder(args)
                  .UseContentRoot(directory.FullName)
                  .Build()
                  .Run();
          }
  
          public static IHostBuilder CreateHostBuilder(string[] args) =&gt;
              Host.CreateDefaultBuilder(args)            
                  .ConfigureWebHostDefaults(webBuilder =&gt;
                  {
                      webBuilder.UseStartup&lt;Startup&gt;();
                  });
      }
  </code></pre>
  <p>While I appreciate that this seems like a hack (I couldn't find any official documentation for this path), I wanted to have some working code.</p>
  <p>With these changes page now loads static resources, not all of them though.</p>
  <p>This is the content of <code>wwwroot</code> folder in the solution explorer</p>
  <p><a href="https://i.stack.imgur.com/nOjD7.png" rel="noreferrer"><img src="https://i.stack.imgur.com/nOjD7.png" alt="enter image description here" /></a></p>
  <p>And this is the content of extracted <code>wwwroot</code> folder on the temp path</p>
  <p><a href="https://i.stack.imgur.com/JW8nW.png" rel="noreferrer"><img src="https://i.stack.imgur.com/JW8nW.png" alt="enter image description here" /></a>
  <a href="https://i.stack.imgur.com/Rvh43.png" rel="noreferrer"><img src="https://i.stack.imgur.com/Rvh43.png" alt="enter image description here" /></a></p>
  <p>As can be seen <code>js/css</code> folders are missing altogether as well as <code>jquery-validation</code> &amp; <code>jquery-validation-unobtrusive</code> folders.</p>
  <p>Any clue what's going on ?</p>
  <p>I created a <a href="https://github.com/gmanvel/AspNetCoreSingleFileApp" rel="noreferrer">github repo</a> with latest changes.</p>