dotnet / sdk

Core functionality needed to create .NET Core projects, that is shared between Visual Studio and CLI
https://dot.net/core
MIT License
2.68k stars 1.06k forks source link

Self-contained deployment of WinForms always includes WPF assemblies #4078

Open filipnavara opened 4 years ago

filipnavara commented 4 years ago

Moved from https://github.com/dotnet/winforms/issues/2426. Related: https://github.com/mono/linker/issues/832

Problem description:

Actual behavior:

Published output contains large part of WPF stack (eg. PresentationCore.dll, PresentationUI.dll, PresentationFramework*.dll, etc.) which amounts to over 30 Mb (> 10 Mb compressed) of unused assemblies. The files are pulled from the "runtimepack.Microsoft.WindowsDesktop.App.Runtime.win-x86/3.0.0" NuGet package.

Expected behavior:

No WPF assemblies in the output. They should either not be included or they should get trimmed out.

Minimal repro:

WindowsFormsApp1.zip

ericstj commented 4 years ago

/cc @swaroop-sridhar @jeffschwMSFT

jeffschwMSFT commented 4 years ago

@sbomer

wangfu91 commented 4 years ago

I'm running into the same issue, is there any plan to fix this in the .NET 5.0 time frame?

NN--- commented 3 years ago

You can use explicit FrameworkReference to WindowsForms.

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

  <PropertyGroup>
    <TargetFramework>net5.0</TargetFramework>
    <!-- Use explicit  -->
    <DisableImplicitFrameworkReferences>true</DisableImplicitFrameworkReferences>
  </PropertyGroup>

  <ItemGroup>
    <!-- .NET Runtime -->
    <FrameworkReference Include="Microsoft.NETCore.App" />

    <!-- Windows Forms -->
    <FrameworkReference Include="Microsoft.WindowsDesktop.WindowsForms”  />   
  </ItemGroup>

</Project>

I use this technique in my project to prevent adding Windows Forms assemblies to Console application https://habr.com/ru/post/549530/

AraHaan commented 2 years ago

For .NET 6 and 5 When I specify UseWinForms to true in project it should exclude referencing the wpf assemblies entirely unless you also set UseWPF to true as well.