maui
maui copied to clipboard
Expose the types/interfaces in Maui Essentials as a separate library targeting net6.0
Description
Have created a Razor Class Library (RCL) with the intention of sharing it with other Blazor targets.
In order to use some of the Essentials API (interface-based implementation), enabled it using the project option <UseMauiEssentials>true</UseMauiEssentials>. With this, the RCL compiled without any issues and the corresponding the .NET MAUI App also worked as expected.
When this RCL is added as a reference to the Blazor WebAssembly app, getting an error that Microsoft.Maui.dll is missing. So enabled the Maui Essentials option over there too. But since there's no assembly available for the WebAssembly targets, couldn't able to refer the interfaces for JS-based implementation.
Hence request to expose the types/interfaces in the Maui Essentials library as a separate library targeting .NET 6. This is critical for referencing RCL with all possible Blazor targets to maximize code sharing.
Steps to Reproduce
- Create a new Razor Class Library (RCL)
- Enable the Maui Essentials with
<UseMauiEssentials>true</UseMauiEssentials>in the project file - Add any API, say Connectivity, to the RCL
- Create a new Blazor WebAssembly (WASM) project
- Add the newly created RCL as a reference to this WASM project and try to build
Version with bug
Preview 14 (current)
Last version that worked well
Unknown/Other
Affected platforms
Other (Tizen, Linux, etc. not supported by Microsoft directly)
Affected platform versions
.NET 6 Blazor Targets
Did you find any workaround?
Nope
Relevant log output
MicrosoftNetCoreAppRuntimePackRidDir=C:\Program Files\dotnet\packs\Microsoft.Maui.Essentials.Runtime.any\6.0.200-preview.14.5099\runtimes\browser-wasm\ doesn't exist
@egvijayanand Thank you so much for your bug report! Unfortunately, we cannot reproduce your issue with the information above, could you provide a sample project/screenshots or more details that we can reproduce your issue? That should greatly speed up the process, thanks!
Hi @egvijayanand. We have added the "s/needs-repro" label to this issue, which indicates that we require steps and sample code to reproduce the issue before we can take further action. Please try to create a minimal sample project/solution or code samples which reproduce the issue, ideally as a GitHub repo that we can clone. See more details about creating repros here: https://github.com/dotnet/maui/blob/main/.github/repro.md
This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.
Hi @kristinx0211,
It's a quite straightforward simulation, just created a Blazor WebAssembly project, added <UseMauiEssentials>true</UseMauiEssentials> in the project file, and then defined the following namespace in the _Imports.razor and finally built the project resulting in the reported error as depicted in the below image.
Project file:
<UseMauiEssentials>true</UseMauiEssentials>
_Imports.razor:
@using Microsoft.Maui.ApplicationModel.DataTransfer
Error message:

C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.WebAssembly.Sdk\6.0.4\Sdk\WasmApp.targets(193,5): error : MicrosoftNetCoreAppRun timePackRidDir=C:\Program Files\dotnet\packs\Microsoft.Maui.Essentials.Runtime.any\6.0.300-rc.1.5355\runtimes\browser-wasm\ doesn't exist [E:\Tasks\Mobile\MAUI\RC1\Issue5914\Issue5914\Issue5914.csproj]
Attached is the source for the same:
Regards, Vijay Anand E G
Adding it to RCL and referencing it in the application will have the same effect as Essentials becomes a dependent assembly to load the RCL in the Blazor application.
@egvijayanand thanks for your update. but I am not repro your issue with the above project. I can build and run succeed. is this as your expect result?

Hi @kristinx0211,
It's quite unfortunate the issue is not getting reproduced at your end.
Here is the build log for the project that I shared earlier.
.NET Version is the latest preview version compatible with .NET MAUI and using VS2022 17.2 Preview 3.0
Is the system that you're trying anything different than the one above?

Kindly let me know how to take this further.
Regards, Vijay Anand E G
Hello Team,
Since this issue is not addressed as part of the .NET 7 release and it still ends up in the same error.
Since the interface is the key to injecting dependencies into the DI container and sharing code across platforms, may I know when this will be taken up?
C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.WebAssembly.Sdk\7.0.0\Sdk\WasmApp.targets(246,5): error : MicrosoftNetCoreAppRuntimePackRidDir=C:\Program Files\dotnet\packs\Microsoft.Maui.Essentials.Runtime.any\7.0.49\runtimes\browser-wasm\ doesn't exist [E:\Projects\NET 7\EssentialsTesting\EssentialsTesting.csproj]
Regards, Vijay Anand E G
Verified this on Visual Studio Enterprise 17.6.0 Preview 3.0. Does not repro on Windows 11 with below Project: 5914.zip
