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

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

Open
filipnavara opened this issue Dec 19, 2019 · 5 comments
Open

Comments

@filipnavara
Copy link
Member

Moved from dotnet/winforms#2426. Related: dotnet/linker#832

  • .NET Core Version: 3.0; 3.1
  • Have you experienced this same bug with .NET Framework?: No

Problem description:

  • Create a simple WinForms application (either through dotnet new or VS)
  • Add Publish profile, change it from "framework dependent" to "self-contained"
  • Enable PublishTrimmed

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
Copy link
Member

ericstj commented Jan 9, 2020

/cc @swaroop-sridhar @jeffschwMSFT

@jeffschwMSFT
Copy link
Member

@sbomer

@wangfu91
Copy link

wangfu91 commented Sep 7, 2020

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

@NN---
Copy link
Contributor

NN--- commented Mar 30, 2021

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
Copy link
Member

AraHaan commented Dec 22, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants