question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Blazor WebAssembly Shared UI Library

See original GitHub issue

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

Adding a project reference from a Blazor WebAssembly project to a Razor Class Library produces NETSDK1082 There was no runtime pack for Microsoft.AspNetCore.App available for the specified RuntimeIdentifier 'browser-wasm'.

Expected Behavior

Use case: I wish to store my UI and logic in a shared class library that can be accessed by both a Blazor WASM app and a Blazor MAUI app, so I create a Razor Class Library to hold this logic.

I would expect that you would be able to reference a Razor Class Library from a Blazor WebAssembly application.

Steps To Reproduce

A demonstration solution is available here: https://github.com/Foxtrek64/BlazorSharedUI This solution contains three projects:

  • A Maui Blazor app built from the default .NET 7 template, unmodified.
  • A Razor Class Library. I’ve deleted the default Areas directory, added a Pages directory, and copied in the Index.razor file from the Blazor WebAssembly application.
  • A Blazor WebAssembly application built with the Empty template, with Linux Docker support and PWA support.

Building the Blazor WebAssembly app and running it results in exactly what you might expect - the browser opens and shows Hello World as described by the default Index.razor file.

Steps to reproduce:

  1. Right click on BlazorSharedUI.Web -> Add -> Project Reference…
  2. Add a reference to BlazorSharedUI.Shared
  3. Click OK
  4. Run the app again. The NETSDK1082 exception is thrown at build.

The Maui Blazor app is not required for this demo, but I added it for completeness. Ideally, both of these projects would reference the .Shared library and pull their UI from there, but I can’t even get them to reference the library without catching on fire.

Exceptions (if any)

No response

.NET Version

7.0.100

Anything else?

There are many suggestions out there, such as #27738, suggest changing the project SDK of the shared project from Microsoft.NET.Sdk.Razor to Microsoft.NET.Sdk. Making this change simply produces a second error and has a tangential effect of no longer recognizing the wwwroot folder if one is present in the project (icon changes from a globe to the standard folder icon):

MSB4057 The target "RazorGenerateComponentDesignTime" does not exist in the project.

Issue Analytics

  • State:open
  • Created 10 months ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
mkArtakMSFTcommented, Dec 5, 2022

Thanks for contacting us. Looks like you’ve checked the Support pages and views option when you were creating the Razor Class Library project. Referencing these projects from a Blazor WebAssembly project is not supported. consider creating the project without that flag checked: https://github.com/Foxtrek64/BlazorSharedUI/blob/f98f2cce9b9413dc8e473df217492ba27c6f9c81/BlazorSharedUI.Shared/BlazorSharedUI.Shared.csproj#L7

0reactions
andrewaggbcommented, May 6, 2023

So to be clear - Is the current state of things that I can’t share a Page in an RCL library between wasm and server? I can share static content and components but not pages?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Share assets across web and native clients using a Razor ...
Reusable Razor UI in class libraries with ASP.NET Core. The examples in this article share assets between a Blazor Server app and a...
Read more >
Share Blazor Components with Shared Class Libraries
This post shows you how you can share Blazor components with ... Select the Blazor template (Blazor Server App or Blazor WebAssembly App) ......
Read more >
Shared Component / Page library using a UI Framework
I was able to have a shared library work with WASM, BlazorServer (signalr), MAUI, and WindowsForms hybrid. Mudblazor across all of them and ......
Read more >
8 Free and Open Source Blazor UI Libraries
Free and open-source user interface libraries for Blazor provide access to great-looking, pre-implemented controls, and components.
Read more >
Top 10 nice free Blazor components | by Alexandre Malavasi
5. BlazorStrap. As the name suggests, the one is a UI framework for Blazor focused on Bootstrap. Despite there are many options to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found