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://stackoverflow.com/a/57874357/1099519 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:
app.UseStaticFiles();
in the web application.webBuilder.UseStaticWebAssets();
in the web application.wwwroot\css\Base.css
is set to Content.<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://stackoverflow.com/a/59574845/1099519 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)?
I created a sample on Github for reproduction: https://github.com/DominikAmon/RclIssueDemo
If you remove the reference to Microsoft.AspNet.Core from the RclDemo.Library project, then everything works as expected. This is the line that should be removed from the project file:
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />
If you create a new .NET Core 3.x application, you would not include this reference as it is now included as part of the Microsoft.AspNetCore.App framework reference. Static files worked differently in .NET Core 2.2 Razor Class Libraries, and I think your inclusion of the Microsoft.AspNetCore.Mvc v2.2.0 library is breaking things. There used to be additional configuration to include static files in an RCL.
Shawn