Skip to content
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

Blazor WebAssembly is loading unnecessary dll. #25949

Closed
GTmAster opened this issue Sep 16, 2020 · 7 comments
Closed

Blazor WebAssembly is loading unnecessary dll. #25949

GTmAster opened this issue Sep 16, 2020 · 7 comments
Labels
area-blazor Includes: Blazor, Razor Components feature-blazor-wasm This issue is related to and / or impacts Blazor WebAssembly

Comments

@GTmAster
Copy link

GTmAster commented Sep 16, 2020

I'm trying to use Blazor WebAssembly hosted by ASP.NET Core. After implementing a page, I saw in Chrome DevTools many of unnecessary dlls are transmitted to client. There is an example of situation. Let's assume we have following structure of projects in the solution:

BlazorApp.Client (contains Blazor pages)
    Reference to BlazorApp.Shared
BlazorApp.Server (contains ASP.NET core)
    Reference to BlazorApp.Client
    Reference to BlazorApp.Shared
BlazorApp.Shared (contains shared classes)
    Reference to ClassLibrary
ClassLibrary (contains some more shared classes)
    NuGet reference to AWSSDK.Core
    MyEnum.cs (enum, which is used in Blazor page; not using AWS SDK)

So basically BlazorApp.Shared project has reference to some other project, which could have many nuget packages. Minimum code to reproduce the issue is available in repo https://github.com/GTmAster/blazor-treeshake

My assumption is Mono Linker does a tree shaking in Release build, so all unused code and libraries will be excluded from resulting web assembly. But when I run my app, I see it loads AWSSDK.Core.dll from the server. Code in BlazorApp.Client doesn't use it, as well as the code in BlazorApp.Server and in BlazorApp.Shared. It is only loaded, because it is referenced in ClassLibrary.

DevTools

Am I getting the wrong idea about Mono Linker tree shaking? Is the only way to exclude this dll from shipping is to move MyEnum to BlazorApp.Shared and break BlazorApp.Shared -> ClassLibrary reference?

To Reproduce

Minimum code to reproduce the issue is available in repo https://github.com/GTmAster/blazor-treeshake

Further technical details

  • ASP.NET Core version: 3.1.402
  • dotnet --info:
.NET Core SDK (reflecting any global.json):
 Version:   3.1.402
 Commit:    9b5de826fd

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.17763
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\3.1.402\

Host (useful for support):
  Version: 3.1.8
  Commit:  9c1330dedd

.NET Core SDKs installed:
  3.1.100-preview3-014645 [C:\Program Files\dotnet\sdk]
  3.1.302 [C:\Program Files\dotnet\sdk]
  3.1.401 [C:\Program Files\dotnet\sdk]
  3.1.402 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.1.20 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.1.22 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.20 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.1.22 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.0-preview3.19555.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.1.20 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.22 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.0-preview3.19553.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.1.0-preview3.19553.2 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 3.1.6 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 3.1.8 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  • The IDE : Visual Studio 2019 16.7.3, app is run via command line outside IDE
@SteveSandersonMS
Copy link
Member

Mono Linker does a tree shaking in Release build,

Tree shaking (linking) happens on publish only.

Could you please try publishing your application and see if you still think it loads unnecessary assemblies? Thanks!

@SteveSandersonMS SteveSandersonMS added Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. area-blazor Includes: Blazor, Razor Components feature-blazor-wasm This issue is related to and / or impacts Blazor WebAssembly labels Sep 16, 2020
@GTmAster
Copy link
Author

@SteveSandersonMS
Tried with publish dotnet publish -c Release BlazorApp.sln. AWSSDK.Core.dll is still loaded by client.

@ghost ghost added Needs: Attention 👋 This issue needs the attention of a contributor, typically because the OP has provided an update. and removed Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. labels Sep 16, 2020
@SteveSandersonMS SteveSandersonMS added Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. and removed Needs: Attention 👋 This issue needs the attention of a contributor, typically because the OP has provided an update. labels Sep 16, 2020
@SteveSandersonMS
Copy link
Member

By default the linker only strips code from framework assemblies, not from NuGet packages you reference.

@pranavkm Do you know if we have docs anywhere on how to customize what gets linked?

@ghost ghost added Needs: Attention 👋 This issue needs the attention of a contributor, typically because the OP has provided an update. and removed Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. labels Sep 16, 2020
@mkArtakMSFT mkArtakMSFT removed the Needs: Attention 👋 This issue needs the attention of a contributor, typically because the OP has provided an update. label Sep 16, 2020
@mkArtakMSFT mkArtakMSFT added this to the Discussions milestone Sep 16, 2020
@pranavkm
Copy link
Contributor

@GTmAster
Copy link
Author

GTmAster commented Sep 17, 2020

@pranavkm
Thanks for the link to documentation about trimming. I have added following properties to BlazorApp.Client.csproj and BlazorApp.Shared.csproj:

	<PublishTrimmed>true</PublishTrimmed>
	<TrimMode>link</TrimMode>
	<RuntimeIdentifier>browser-wasm</RuntimeIdentifier>

Tried to publish it with dotnet publish -c Release and dotnet publish -c Release --self-contained true.

But it didn't help. AWSSDK.Core.dll is still loaded by browser. Am I missing here something?

@ghost
Copy link

ghost commented Nov 16, 2020

Thank you for contacting us. Due to a lack of activity on this discussion issue we're closing it in an effort to keep our backlog clean. If you believe there is a concern related to the ASP.NET Core framework, which hasn't been addressed yet, please file a new issue.

This issue will be locked after 30 more days of inactivity. If you still wish to discuss this subject after then, please create a new issue!

@ghost ghost closed this as completed Nov 16, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 16, 2020
@Pilchie Pilchie removed this from the Discussions milestone Feb 9, 2021
@Pilchie
Copy link
Member

Pilchie commented Feb 9, 2021

Re-opening. This probably shouldn't have been in Discussions.

Ping @SimonCropp

This issue was closed.
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

5 participants