question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Self-contained deployment of WinForms always includes WPF assemblies

See original GitHub issue

Moved from https://github.com/dotnet/winforms/issues/2426. Related: https://github.com/mono/linker/issues/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

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:5
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
AraHaancommented, 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.

0reactions
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/

Read more comments on GitHub >

github_iconTop Results From Across the Web

Create a single file for application deployment - .NET
The size of the single file in a self-contained application is large since it includes the runtime and the framework libraries.
Read more >
3 Ways to Deploy a WinForms or WPF .NET Core Application
This post will help you deploy and bring your finished app to your users. .NET Core 3 gives us three ways to deploy...
Read more >
[RESOLVED] .NET 6 Winform App with Setup & ...
To deploy a Winforms app developed using .NET 6 using the Visual Studio Installer (Setup & Deployment project), you have to trick the...
Read more >
c# - Possible to ship my application with a local copy of the ...
NET 7 applications (Console and WinForms) that all sit in the same folder of a product of mine, I try to find a...
Read more >
Deploy .NET Applications | WPF Controls
Self-Contained Deployment. Published application includes all its dependencies and the .NET runtime. This mode allows you to deploy your application to any ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found