Skip to content

dotnet publish -c Release fail with <RunAOTCompilation>true</RunAOTCompilation> and <BlazorWebAssemblyLazyLoad #60479

Closed

Description

@aguacongas

Description

If we want to compile a Blazor project with AOT and lazy loading the command dotnet publish -c Release fail with error :

error BLAZORSDK1001: Unable to find '[lazy load assembly name].dll' to be lazy loaded later. Confirm that project or package references are included and the reference is used in the project.

Reproduction Steps

  • Create a blazor wasm project
  • Create a razor class library project
  • Add a project reference to for the razor class library project to the blazor wasm project
  • Add a BlazorWebAssemblyLazyLoad instruction for the razor class library assembly in the blazor wasm project
  • Add true in the blazor wasm project
  • try to publish the blazor wasm project with dotnet publish -c Release

ex:

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

  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
    <RunAOTCompilation>true</RunAOTCompilation>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="6.0.0-rc.2.21480.10" />
    <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="6.0.0-rc.2.21480.10" PrivateAssets="all" />
    <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Authentication" Version="6.0.0-rc.2.21480.10" />
  </ItemGroup>

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

  <ItemGroup>
    <BlazorWebAssemblyLazyLoad Include="RazorClassLibrary.dll" />
  </ItemGroup>
  
</Project>

Expected behavior

The publish command should run without error

Actual behavior

The publish command fail with :

error BLAZORSDK1001: Unable to find '[razor class library name].dll' to be lazy loaded later. Confirm that project or package references are included and the reference is used in the project.

Regression?

No response

Known Workarounds

No response

Configuration

❯ dotnet --info
.NET SDK (reflecting any global.json):
 Version:   6.0.100-rc.2.21505.57
 Commit:    ab39070116

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.19042
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\6.0.100-rc.2.21505.57\

Host (useful for support):
  Version: 6.0.0-rc.2.21480.5
  Commit:  6b11d64e7e

.NET SDKs installed:
  1.1.14 [C:\Program Files\dotnet\sdk]
  2.2.207 [C:\Program Files\dotnet\sdk]
  3.1.402 [C:\Program Files\dotnet\sdk]
  5.0.205 [C:\Program Files\dotnet\sdk]
  5.0.402 [C:\Program Files\dotnet\sdk]
  6.0.100-rc.2.21505.57 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.All 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.2.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.2.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.20 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.0-rc.2.21480.10 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 1.0.16 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 1.1.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.2.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.20 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.0-rc.2.21480.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.1.4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 3.1.8 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 3.1.20 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 5.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 5.0.5 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 5.0.8 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 5.0.11 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 6.0.0-rc.2.21501.6 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

To install additional .NET runtimes or SDKs:
  https://aka.ms/dotnet-download

Other information

No response

Activity

  1. transferred this issue fromdotnet/runtimeon Oct 14, 2021
  2. pranavkm commented on Oct 15, 2021

    @pranavkm
    Contributor

    @radical it looks related to #60274. I have a binlog at "\prkrishn-foo\share\msbuild.binlog" in case it helps, but it's fairly trivial to reproduce this with a regular blazor-wasm app.

    Publish runs twice

    image

    and in the first one a bunch of MSBuild properties aren't resolved which results in this error:

    First publish:
    image

    ^ Notice Resources is missing

    Second publish:
    image

    The first one is kicked off by WasmNestedPublishApp. More worrying is that it's sufficient to have the tool installed (without required AOT compilation) to run in to this issue:

    > dotnet publish
    Microsoft (R) Build Engine version 17.0.0-preview-21474-03+9f83c725f for .NET
    Copyright (C) Microsoft Corporation. All rights reserved.
    
      Determining projects to restore...
      All projects are up-to-date for restore.
      You are using a preview version of .NET. See: https://aka.ms/dotnet-core-preview
      rc1 -> D:\temp\testapps\b1\rc1\bin\Debug\net6.0\rc1.dll
      b1 -> D:\temp\testapps\b1\b1\bin\Debug\net6.0\b1.dll
      b1 (Blazor output) -> D:\temp\testapps\b1\b1\bin\Debug\net6.0\wwwroot
      Optimizing assemblies for size, which may change the behavior of the app. Be sure to test after publishing. See: https://aka.ms/dotnet-illink
      rc1 -> D:\temp\testapps\b1\rc1\bin\Debug\net6.0\rc1.dll
      b1 -> D:\temp\testapps\b1\b1\bin\Debug\net6.0\b1.dll
      b1 (Blazor output) -> D:\temp\testapps\b1\b1\bin\Debug\net6.0\wwwroot
      Optimizing assemblies for size, which may change the behavior of the app. Be sure to test after publishing. See: https://aka.ms/dotnet-illink
    D:\temp\dotnet6\sdk\6.0.100-rc.2.21505.1\Sdks\Microsoft.NET.Sdk.BlazorWebAssembly\targets\Microsoft.NET.Sdk.BlazorWebAssembly.6_0.targets(524,5): error BLAZORSDK1001: Unable to find 'rc1.dll' to be lazy loaded later. Confirm that project or package references are included and the reference is used in the project. [D:\temp\testapps\b1\b1\b1.csproj]
    
  3. radical commented on Oct 15, 2021

    @radical
    Member

    it looks related to #60274.

    That one is failing with The command "emcc --version" exited with code 1., and seems unrelated.

    This is my understanding of what's happening here:

    1. For the nested publish, we essentially run Publish target, and then the wasm native targets run

    2. during the Publish part of it:
      a. we get to ProcessPublishFilesForBlazor, which currently we skip for the nested publish case ($(WasmBuildingForNestedPublish))

      • and this target populates @(StaticWebAsset), when run

      b. Then we get to GeneratePublishBlazorBootJson, which fails because it doesn't have the StaticWebAssets correctly populated, and thus can't find the lazy loaded assembly

    Please correct me if I didn't that right. I don't really understand the static web assets part.

    • To fix this, I tried removing the condition on ProcessPublishFilesForBlazor so it would run for nested publish also.

      • but this causes the build to fail because @(WasmAssembliesToBundle) is empty
    • That seems to be because ProcessPublishFilesForBlazor removes items from ResolveFileToPublish

      • which causes _GatherWasmFilesForPublish to fail as it depends on @(ResolvedFileToPublish) to populate @(WasmAssembliesToBundle)

    If this line of thinking is correct, then maybe we can instead of @(StaticWebAsset):

    - <WasmAssembliesToBundle Include="%(ResolvedFileToPublish.FullPath)" Exclude="@(_Exclude)" Condition="%(Extension) == '.dll'" />
    + <WasmAssembliesToBundle Include="%(StaticWebAsset.FullPath)" Exclude="@(_Exclude)" Condition="%(Extension) == '.dll'" />

    I'm not sure if this is the correct fix or not. @javiercn thoughts?

    Our blazorwasm tests fail with this though, because there are more than one dotnet*js files in the publish folder:

    /Users/radical/dev/r3/artifacts/bin/Wasm.Build.Tests/net6.0-Release/browser-wasm/blz_aot_prj_file_Debug/bin/Debug/net6.0/publish/wwwroot/_framework/dotnet.6.0.0-rc.2.21470.23.bc68qmiu8q.js
    /Users/radical/dev/r3/artifacts/bin/Wasm.Build.Tests/net6.0-Release/browser-wasm/blz_aot_prj_file_Debug/bin/Debug/net6.0/publish/wwwroot/_framework/dotnet.6.0.0-rc.2.21470.23.c0ti6blhkl.js
    

    For future (7.0) work, the targets can be reworked a bit to reduce the amount of work we do in the nested publish, and better integrate it.

    cc @lewing

  4. srpeirce commented on Oct 15, 2021

    @srpeirce

    This is duplicate to this issue? dotnet/aspnetcore#37570

    The linked issue has same issue but AOT is disabled. It is using wasm-tools.

    Minimal example linked in the project if helpful.

  5. pranavkm commented on Oct 15, 2021

    @pranavkm
    Contributor

    @srpeirce the presence of the wasm-tools is sufficient to trigger the same code that appears as part of AOT.

  6. transferred this issue fromdotnet/aspnetcoreon Oct 15, 2021
  7. ghost added
    untriagedNew issue has not been triaged by the area owner
    on Oct 15, 2021
  8. removed their assignment
    on Oct 15, 2021
  9. pranavkm commented on Oct 15, 2021

    @pranavkm
    Contributor

    @radical transferring this over to you.

  10. removed
    untriagedNew issue has not been triaged by the area owner
    on Oct 15, 2021
  11. self-assigned this
    on Oct 15, 2021
  12. added this to the 6.0.0 milestone on Oct 15, 2021
  13. radical commented on Oct 19, 2021

    @radical
    Member

    Fixed by dotnet/sdk#22145 . I will port this to main also.

  14. ghost locked as resolved and limited conversation to collaborators on Nov 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions