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.

Use UseMaui=true in a razor component breaks the _content/PackageId

See original GitHub issue

Description

Adding <UseMaui>true</UseMaui> to a razor component library causes the static we assets not to be packaged correctly.

I think this has to do with the fact our maui blazor targets assume an app and thus force set the BasePath to be / instead of first checking the context - final app or library,

Steps to Reproduce

  1. Create a maui blazor app that references a plain razor component library
  2. Observe a successful run
  3. Add UseMaui=true to the razor compoent
  4. Observe that the razor component no longer loads

Expected Behavior

Actual Behavior

Basic Information

  • Version with issue:
  • Last known good version:
  • IDE:
  • Platform Target Frameworks:
    • iOS:
    • Android:
    • UWP:
  • Android Support Library Version:
  • Nuget Packages:
  • Affected Devices:

Screenshots

Reproduction Link

Workaround

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
Eiloncommented, Jan 25, 2022

The workaround is to:

  1. Place all the Razor code (*.razor files) in a regular Razor Class Library (RCL)
  2. The .NET MAUI library can have <UseMaui>true</UseMaui> and reference the RCL for whatever types it needs
0reactions
densen2014commented, Jun 11, 2023

try only use maui in ios and mac ,

	<PropertyGroup Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst' or $([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">
		<UseMaui>true</UseMaui>	
		<SingleProject>true</SingleProject>
	</PropertyGroup>

and

    <!--启用maui支持,直接忽略共享库并到主项目,所以不用引用共享库名称-->
    <link href="css/app.css" rel="stylesheet" />
    <!--不启用maui支持,引用共享库名称的css-->
    <link href="_content/BlazorHybrid.Shared/css/app.css" rel="stylesheet" />
Read more comments on GitHub >

github_iconTop Results From Across the Web

Use "Razor component" and avoid "Blazor ...
Description I'm going to move this over from a GH discussion because I'm having good luck thus far getting MS pubs updated on...
Read more >
ASP.NET Core Razor component lifecycle
The Razor component processes Razor component lifecycle events in a set of synchronous and asynchronous lifecycle methods. The lifecycle methods ...
Read more >
Use Razor components in JavaScript apps and SPA ...
This article covers how to render Razor components from JavaScript, use Blazor custom elements, and generate Angular and React components.
Read more >
Auto-formatting in EditForm razor code breaks binding ...
I'm experimenting with EditForm component tag and related Input child tags. The Input tag (e.g. InputText) expect binding with a @bind-Value ...
Read more >
Can Blazor component interaction occur inside a Razor ...
Is it possible to use a component to create a dynamic Razor pages form, or does the entire form need to be moved...
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