Skip to content

Blazor WASM with linker enabled downloads unused dependencies during boot #22230

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
isc30 opened this issue May 26, 2020 · 2 comments
Closed
Labels
area-blazor Includes: Blazor, Razor Components feature-blazor-wasm This issue is related to and / or impacts Blazor WebAssembly

Comments

@isc30
Copy link

isc30 commented May 26, 2020

The linker in Blazor WASM is including dependencies that aren't in use (in normal scenarios these would be stripped out by the compiler, which is what happens with the linker disabled (ok)).

When adding a reference (RCL project/nuget) to a project with Microsoft.AspNetCore.Components.WebAssembly.Build and BlazorWebAssemblyEnableLinking set to true, the linker will add the dependency project as a boot dependency inside blazor.boot.json even if it's not used at all.

If this reference is not used, the linker should detect it and not add it as a boot project. I suspect the problem is somewhere where we take the linker output and enumerate the blazor binaries based on it.

This issue doesn't happen with BlazorWebAssemblyEnableLinking disabled (the unused project is not even inside _framework/_bin) but StaticWebAssets are still there (ok).

To Reproduce

Please follow the steps to get this reproduced on your own repository.
In order to check the bug, this minimal example repository with the bug can be used.

Properly Working Example: With no Linker

  1. Create a Blazor WASM project (host)
  2. Add <BlazorWebAssemblyEnableLinking>false</BlazorWebAssemblyEnableLinking>
  3. Create a RCL project (lib) with a Component and wwwroot/test.css as StaticWebAsset
  4. Reference lib from host and use the Component from it
  5. Build and Run
  6. The DLL of lib appears inside blazor.boot.json and gets downloaded during startup (ok)
  7. Navigate to _content/lib/test.css and see that the StaticWebAsset is available (ok)
  8. Remove the runtime usage of lib by not using the Component anymore so the compiler strips it out
  9. The DLL of the project is no longer inside blazor.boot.json and doesn't get downloaded during startup (ok)
  10. The StaticWebAsset _content/lib/test.css is still available (ok)

Buggy Example: With Linker enabled

  1. Use the project from the working example
  2. Change it to use <BlazorWebAssemblyEnableLinking>true</BlazorWebAssemblyEnableLinking>
  3. Reference lib from host and use the Component from it
  4. Build and Run
  5. The DLL of lib appears inside blazor.boot.json and gets downloaded during startup (ok)
  6. Navigate to _content/lib/test.css and see that the StaticWebAsset is available (ok)
  7. Remove the runtime usage of lib by not using the Component anymore so the compiler strips it out
  8. The DLL of the project is still inside blazor.boot.json and still gets downloaded during startup (fail)
  9. The StaticWebAsset _content/lib/test.css is still available (ok)

Further technical details

  • ASP.NET Core version: 3.2.0-rc1.20223.4
  • dotnet version: 3.1.201

Comments

This is a rather big bug. When including a NuGet package and using a small portion of it, the linker will still add every sub-reference, even if not used and the DLL could be skipped.

This should still preserve StaticWebAssets from the projects that don't need a runtime.

isc30 added a commit to isc30/bugs that referenced this issue May 26, 2020
@pranavkm pranavkm added area-blazor Includes: Blazor, Razor Components feature-blazor-wasm This issue is related to and / or impacts Blazor WebAssembly labels May 26, 2020
@mkArtakMSFT
Copy link
Member

Thanks for contacting us.
The linker is only linking the framework binaries at the moment. We will be changing that in the future to trim also application binaries in the future.

@isc30
Copy link
Author

isc30 commented May 28, 2020

Can we at least get an ItemGroup to be able to exclude some assemblies (and subassemblies) from the blazor.boot.json?
Disabling the linker seems useless in this situation

@ghost ghost locked as resolved and limited conversation to collaborators Jun 27, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-blazor Includes: Blazor, Razor Components feature-blazor-wasm This issue is related to and / or impacts Blazor WebAssembly
Projects
None yet
Development

No branches or pull requests

3 participants