I am having difficulties implementing static files in razor class library (.net Core 3.1) that are consumed by an ASP.NET Core (v3.1) application.
When trying to access the static files, I only get an 404 - Not Found.
I followed the following answer on Stackoverflow: https://mcmap.net/q/360913/-can-razor-class-library-pack-static-files-js-css-etc-too or
I also cross-checked with the documentation at: https://learn.microsoft.com/en-us/aspnet/core/razor-pages/ui-class?view=aspnetcore-3.0&tabs=visual-studio#create-an-rcl-with-static-assets.
I placed a css file in the library at the following location:
wwwroot\css\Base.css
and I tested the following path: https://localhost:44300/_content/OurIt.Cockpit/css/Base.css, which results in a 404 Not found response.
What I've already checked:
- Any Controller with its Views inside the RCL can be browsed and they work fine (rendered HTML code is served to the browser)
- Having
app.UseStaticFiles();
in the web application. - Having
webBuilder.UseStaticWebAssets();
in the web application. - Correct Casing.
- The Build Action of
wwwroot\css\Base.css
is set to Content. - The RCL project has the following sdk defined:
<Project Sdk="Microsoft.NET.Sdk.Razor">
. The following properties are set in the RCL project:
<PropertyGroup> <TargetFramework>netcoreapp3.1</TargetFramework> <AddRazorSupportForMvc>true</AddRazorSupportForMvc> <PropertyGroup>
I also tried the way described in this answer: https://mcmap.net/q/360913/-can-razor-class-library-pack-static-files-js-css-etc-too and I tried to access the file from https://localhost:44300/path/css/Base.css
Is there any chance to debug or locate the issue? Reguarding to the Microsoft documentation:
When the RCL is built, a manifest is produced that describes the static web asset locations. The consuming app reads the manifest at runtime to consume the assets from referenced projects and packages.
In order to verify that the files are in the assembly, I was trying to locate that manifrest, but I couldn't find it or don't know where to look for it (i checked the output folder). I also tried opend the RCL with ILSpy hoping to find a glue for the issue.
Any ideas (or working samples with a RCL with static content for .NET Core 3.1 - I only found samples for Controllers / Views but not with static content)?
Update 2020-02-05:
I created a sample on Github for reproduction: https://github.com/DominikAmon/RclIssueDemo
<script src="~/dist..."
with<script src="_content/{LIBRARY}/dist..."
, which gave errors. After looking at your code I changed it to<script src="~/_content/{LIBRARY}/dist..."
. Needed the tilde. – Natality