WebWindow icon indicating copy to clipboard operation
WebWindow copied to clipboard

How to include static assets from RazorLib?

Open Mercurial opened this issue 4 years ago • 8 comments

Hi I'm trying to use MatBlazor library but I can't seem to figure out how to include the js and css files for MatBlazor

@SteveSandersonMS

Thanks!

Mercurial avatar Nov 25 '19 20:11 Mercurial

I tried this but it doesn't seem to work

<link href="/_content/RazorClassLibrary1/styles.css" rel="stylesheet" />
<script src="/_content/RazorClassLibrary1/exampleJsInterop.js"></script>

Mercurial avatar Nov 25 '19 21:11 Mercurial

I did some testing of loading assets from "_content" with Version="0.1.0-20191120.6"

  1. No - VS debug
  2. No - dotnet run
  3. Yes - Publish - Self-Contained
  4. Yes - Publish - Framework Dependent
  5. No - Publish - Self-Contained + Produce single file
  6. No - Publish - Framework Dependent + Produce single file

IvanJosipovic avatar Dec 06 '19 05:12 IvanJosipovic

Unfortunately this is a common issue of any ASP .NET Core application: "Produce single file" option does not generate _content folder with RazorLib assets which should lead to improper work of many Blazor apps.

iberisoft avatar Jan 07 '20 12:01 iberisoft

Bumping this issue, since I am running into iit myself.

What is the cause of the _content folder not generating when using "Produce single file"?

MaverickMartyn avatar Feb 16 '20 04:02 MaverickMartyn

Is there any workaround for VS debug mode? Even an ugly hack would help!

Even if I have to change the source code, just point me in the right direction, thank you!

Jinjinov avatar Mar 16 '20 08:03 Jinjinov

@Jinjinov I haven't tried to implement it myself, but the MSBuild logic needed to copy static web assets into the build output is this: https://github.com/dotnet/aspnetcore/blob/blazor-wasm/src/Components/WebAssembly/Build/src/targets/StaticWebAssets.targets#L37-L72

If you find you're able to make this work and want to submit a PR here, that would be great!

SteveSandersonMS avatar Mar 19 '20 15:03 SteveSandersonMS

Making the assets as embedded worked for me (on the wwwroot folder)

This guide helped https://codeopinion.com/asp-net-core-csproj-embedded-resources/

dangershony avatar Apr 29 '20 09:04 dangershony

I'm really new to blazor, any way to use middleware and fileprovider to _content/resoruce

nmocruz avatar Jun 14 '20 16:06 nmocruz