dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.18k stars 4.72k forks source link

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

Closed aguacongas closed 3 years ago

aguacongas commented 3 years ago

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

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

dotnet-issue-labeler[bot] commented 3 years ago

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

pranavkm commented 3 years ago

@radical it looks related to https://github.com/dotnet/runtime/issues/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]
radical commented 3 years ago

it looks related to dotnet/runtime#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.

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

srpeirce commented 3 years ago

This is duplicate to this issue? https://github.com/dotnet/aspnetcore/issues/37570

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

Minimal example linked in the project if helpful.

pranavkm commented 3 years ago

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

dotnet-issue-labeler[bot] commented 3 years ago

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

pranavkm commented 3 years ago

@radical transferring this over to you.

ghost commented 3 years ago

Tagging subscribers to 'arch-wasm': @lewing See info in area-owners.md if you want to be subscribed.

Issue Details
### 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: ```xml net6.0 enable enable true ``` ### 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 ```bash ❯ 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_
Author: aguacongas
Assignees: -
Labels: `arch-wasm`, `untriaged`, `area-Build-mono`
Milestone: -
radical commented 3 years ago

Fixed by https://github.com/dotnet/sdk/pull/22145 . I will port this to main also.