I'm building a webapp with ASP.Net Core, typescript, react and webpack. It's called Ui.WebApp
. The React app is located at Ui.WebApp/ClientApp
and the webpack build outputs to Ui.WebApp/ClientApp/dist
.
In my Startup.cs
I've included
app.UseStaticFiles(new StaticFileOptions {
FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), "ClientApp/dist"))
}
);
That works i.e. when I load styles in my _Layout.cshtml
as <link rel="stylesheet" href="~/main.css" asp-append-version="true" type="text/css" />
which physically resides in Ui.WebApp/ClientApp/dist/main.css
. It also works for scripts I include as <script src="~/main.js"></script>
.
Now I need to build the scripts in webpack with a hash in their name, i.e. main_968495a262da1789981f.js
. The pattern for that in ASP.Net is to use <script asp-src-include="~/main_*.js"></script>
. However, when viewing the page from a browser, there is no resulting script-tag, as I assume ASP.Net does not find any file matching the pattern (but I can see it in a file explorer).
Strangely, when I manually put the hashed js file into Ui.WebApp/wwwroot
(which I don't use otherwise), the script tags are filled in correctly. They even stay there when I delete the folder and refresh the page.
So I assume ASP.Net validates the tag-helpers on compiletime and thus can't see the configuration I do in the Startup.cs
.
Is there any way to get ASP.Net to validate the tag-helpers during runtime and pick the correct location?