Walter Torricos
Walter Torricos

Reputation: 381

Net 7 XAPRAS7028 System.IO.FileNotFoundException: Could not find file 'bin\Debug\net7.0\browser-wasm\App.dll' when referencing Blazor from MauiBlazor

I have two .net7 projects. A MauiBlazor project created with the default template and a Blazor Web Assembly project created with the default template.

Inside the MauiBlazor project I added a reference to the Blazor project (I made all the necessary updates to reference the Blazor project as well)

The problem is when I try to run the MauiBlazor project, I get the following error:

Error   XAPRAS7028  System.IO.FileNotFoundException: Could not find file 'MauiBlazor\BlazorApp\bin\Debug\net7.0\browser-wasm\BlazorApp.dll'.

The question is, how can I reference a Blazor project from a Maui project? Because adding a normal project reference is not working

<ItemGroup>
      <ProjectReference Include="..\BlazorApp\BlazorApp.csproj" />
    </ItemGroup>

I tried to publish the Blazor project with dotnet publish -c Debug -o bin\Debug\net7.0\browser-wasm but it didn't work.

I realized I can get it to work by manually copying the content of: 'MauiBlazor\BlazorApp\bin\Debug\net7.0\ to MauiBlazor\BlazorApp\bin\Debug\net7.0\browser-wasm and then run it with VS (command line won't work) but I'm sure there must be a better way.

I also created this project where the issue can be reproduced by trying to run the MauiMobileApp project. https://github.com/tico321/MauiReferenceBlazorIssue

Upvotes: 0

Views: 1284

Answers (1)

Walter Torricos
Walter Torricos

Reputation: 381

While answering a question above I found my answer as well. If you want to share pages between Maui and Blazor you need a shared project. A great example of that is the dotnet podcast repository for more context on the repository and how they use blazor hybrid watch this talk.

The repo I created to reproduce the issue was also updated with the solution https://github.com/tico321/MauiReferenceBlazorIssue

What I observed from the podcast repository is that the shared repo csproj file needs to reference the Microsoft.NET.Sdk.Razor SDK and also the Microsoft.AspNetCore.Components.Web package, so it should look like this:

<Project Sdk="Microsoft.NET.Sdk.Razor">

  <PropertyGroup>
    <TargetFramework>net7.0</TargetFramework>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="7.0.0" />
  </ItemGroup>

</Project>

Finally, be careful with the index.html file in Maui and in Blazor. The blazor one needs this script <script src="_framework/blazor.webassembly.js"></script> while the Maui one needs this one <script src="_framework/blazor.webview.js" autostart="false"></script>

Upvotes: 1

Related Questions