5

In my razor components project, I am adding a blazor component library to the solution. I can call the components in the component library from my .app project, but it seems that .css and other files don't load from the Blazor component library. I looked into the component library .csproj file, but I can't figure out what is missing:

<Project Sdk="Microsoft.NET.Sdk.Razor">

    <PropertyGroup>
        <TargetFramework>netstandard2.0</TargetFramework>
        <IsPackable>true</IsPackable>
        <LangVersion>7.3</LangVersion>
    </PropertyGroup>

    <ItemGroup>
        <!-- .js/.css files will be referenced via <script>/<link> tags; other content files will just be included in the app's 'dist' directory without any tags referencing them -->
        <EmbeddedResource Include="content\**\*.js" LogicalName="blazor:js:%(RecursiveDir)%(Filename)%(Extension)" />
        <EmbeddedResource Include="content\**\*.css" LogicalName="blazor:css:%(RecursiveDir)%(Filename)%(Extension)" />
        <EmbeddedResource Include="content\**" Exclude="**\*.js;**\*.css" LogicalName="blazor:file:%(RecursiveDir)%(Filename)%(Extension)" />    
    </ItemGroup>

    <ItemGroup>
        <PackageReference Include="Microsoft.AspNetCore.Components.Browser" Version="3.0.0-preview-19075-0444" />
        <PackageReference Include="Microsoft.AspNetCore.Components.Build" Version="3.0.0-preview-19075-0444" PrivateAssets="all" />
    </ItemGroup>

</Project>
1

2 Answers 2

3

This a limitation with the current release of Razor Components. It can't import static assets from components libraries. As workaround, you should copy them manually until is fixed in next releases.

Sign up to request clarification or add additional context in comments.

1 Comment

Is this still an issue yet? There is an issue on Github for that topic: github.com/aspnet/AspNetCore/issues/13854.
1

Static assets should work now since preview 6. Please read blog post about this topic here: https://devblogs.microsoft.com/aspnet/asp-net-core-and-blazor-updates-in-net-core-3-0-preview-6/

1 Comment

It might seem obvious, but you have to set the "copy to output directory". When I published, VS didn't create the wwwrooot directory until I set "Copy to Output Directory" property to "Copy Always".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.