SteveSandersonMS / WebWindow

.NET Core library to open native OS windows containing web UI on Windows, Mac, and Linux. Experimental.
Apache License 2.0
1.98k stars 215 forks source link

How to include static assets from RazorLib? #22

Open Mercurial opened 4 years ago

Mercurial commented 4 years ago

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 commented 4 years ago

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>
IvanJosipovic commented 4 years ago

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
iberisoft commented 4 years ago

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.

MaverickMartyn commented 4 years ago

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"?

Jinjinov commented 4 years ago

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!

SteveSandersonMS commented 4 years ago

@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!

dangershony commented 4 years ago

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

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

nmocruz commented 4 years ago

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