Share wwwroot across multiple projects

Viewed 1422

I have two ASP.NET Core MVC projects. Both projects have the same files in their wwwroot folders.

My question: is it possible to specify a custom location for the wwwroot folder, so that I could access the same wwwroot folder in both projects?

I have already read similar questions like:

With the help of the above listed questions, I identified two approaches

  • using a virtual directory
  • including the files using app.UseFileServer

However, I was not able to reference the files using relative paths, e.g. in _Layout.html the reference ~/lib/bootstrap/dist/css/bootstrap.min.css does not work.

2 Answers

You can specify a custom WebRoot path in Program.cs:

public static IHostBuilder CreateHostBuilder(string[] args) =>
    Host.CreateDefaultBuilder(args)
      .ConfigureWebHostDefaults(webBuilder =>
      {
         webBuilder.UseWebRoot("C:\path\to\folder");
         webBuilder.UseStartup<Startup>();
      });
Related