With net 7, trying to use a Razor Class Library from a MAUI Balzor App I followed this:
In an empty solution I added the Razor class library and I checked the "Support pages and views" flag. I added the MAUI app to solution and I added to this app the reference to Razor Class Library.
If I run for windows all works but if I run for Android(or IOS) not compile with
There was no runtime pack for Microsoft.AspNetCore.App available for the specified RuntimeIdentifier 'android-x86'
I also add in the Razor class library the _Imports.razor
file with @using Microsoft.AspNetCore.Components.Web
and
<ItemGroup>
<SupportedPlatform Include="browser" />
</ItemGroup>
to Razor class library .csproj project file but nothing changed
I still not tryed to use a library content, just adding the reference and build for a platform different from windows.
In the Visual studio installer I already installed .NET SDK for Android and IOS
If, when I create the Razor library, I not check "Support pages and views", this problem not appear, so the problem appear when the library has the reference to Framework Microsoft.AspNetCore.App that is added in the template when "Support pages and views" is checked
How can I fix the problem?
About this error:
There was no runtime pack for Microsoft.AspNetCore.App available for the specified RuntimeIdentifier 'android-x86'
I searched relevant things and finally found this: Support for MAUI runtimes in ASP.NET Core. It said that:
Code that is specific to ASP.NET Core scenarios, such as hosting Kestrel, requires platform support, which as you discovered, it not available on some platforms, such as Android. I think this might really be a question for the ASP.NET folks as to whether there is a desire to support certain features, such as Kestrel, on "arbitrary" platforms, or whether to specifically add support to particular platforms (e.g. android-x86).
This should explain your confusion. And you can follow this issue to see if it has any updates in the future.