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.

Razor SDK incompatible with iOS SDK regarding "Content" items

See original GitHub issue

A Blazor Desktop with .NET MAUI project uses a combination of several .NET SDKs (in the “SDK-style project” sense). The iOS and Razor SDKs have a conflict where they disagree about how to process *.razor files that are <Content ... /> items in the project. The Razor SDK converts those to <RazorComponent ... /> items so that the Razor compiler (source generator) can process them. The iOS SDK wants to include them along with <BundleResource ... /> items and include them in the generated PKG file.

Unfortunately the iOS targets seem to encounter a fatal error and in a “default” scenario with no workaround, you end up with MSBuild errors such as these:

Main.razor The path '../../../../../../../../src/Controls/samples/Controls.Sample/Main.razor' would result in a file outside of the app bundle and cannot be used.
         [/Users/eilonlipton/Documents/GitHub/maui/src/Controls/samples/Controls.Sample/Maui.Controls.Sample-net6.csproj]
Pages/Index.razor The path '../../../../../../../../src/Controls/samples/Controls.Sample/Pages/Index.razor' would result in a file outside of the app bundle and cannot be used.
         [/Users/eilonlipton/Documents/GitHub/maui/src/Controls/samples/Controls.Sample/Maui.Controls.Sample-net6.csproj]
_Imports.razor The path '../../../../../../../../src/Controls/samples/Controls.Sample/_Imports.razor' would result in a file outside of the app bundle and cannot be used.
         [/Users/eilonlipton/Documents/GitHub/maui/src/Controls/samples/Controls.Sample/Maui.Controls.Sample-net6.csproj]

I’m not sure if this is a bug in the iOS targets or not, but regardless of that, we don’t want the iOS targets to try to bundle the *.razor files as resources anyway.

So, we need to try to prevent the iOS SDK from even seeing these files as potential bundle resources and let the Razor SDK do its compilation.

One way to solve this is to include some build assets in the .NET MAUI BlazorWebView NuGet package that convert *.razor files that are <Content ... /> items in the projectand convert them to <RazorComponent ... /> so that the iOS targets won’t see them at all, and the Razor SDK will compile them as intended.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
rolfbjarnecommented, Feb 15, 2022

Where in the iOS app bundle do you want the static resources?

We don’t directly put them as iOS resources at all. We want the Razor SDK to see certain files (e.g. wwwroot/**/*) as Razor Static Web Assets. It then needs to convert those to MauiAsset MSBuild items, which is a feature of .NET MAUI. Then the MauiAssets tasks do “stuff” to convert those to whatever iOS/Android/Windows/MacCatalyst need on their systems (which, in iOS, is presumably a BundleResource?).

Sounds like the same approach of having a custom metadata on Content items that tells us to not bundle those items in the app bundle would help here too.

1reaction
rolfbjarnecommented, Feb 16, 2022

I’m implementing support for the PublishFolderType on Content (and BundleResource) items for the next preview (14): https://github.com/xamarin/xamarin-macios/pull/14162.

Set PublishFolderType=None to prevent these items from being copied to the app bundle.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Microsoft.NET.Sdk.Razor.SourceGenerators can't find ...
Project fails to build Razor pages/components with Razor component when building a MAUI hybrid project for a net6.0-android target . (EDIT: ...
Read more >
ASP.NET Core Razor SDK
Learn how Razor Pages in ASP.NET Core makes coding page-focused scenarios easier and more productive than using MVC.
Read more >
"'Razorpay' was created for incompatible target arm64- ...
After importing Razorpay plugin in flutter, my app is not building for iOS simulator. It is running on iOS Physical device and Android...
Read more >
Assembly location for Razor SDK Tasks was not specified. ...
"Assembly location for Razor SDK Tasks was not specified. The most likely cause is an older incompatible version of Microsoft.NET.Sdk.Razor, or ...
Read more >
Troubleshooting & FAQs
Troubleshoot common error scenarios and find answers to frequently asked questions about standard iOS integration.
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