How can I exclude transitive dependencies that are not needed in the project when publishing my application?

Schmidlin Tizian 0 Reputation points
2023-06-05T08:51:34.61+00:00

Hi there,

I'm building my first real c#.net app using Windows Forms and I used ChatGPT a lot for this as I'm only using Visual Studio Code and have no good way to kickstart my project in any other way. This all worked fine and I came to a point where I wanted to publish my program when I was hit by the brick wall that are the 200MB of generated code I'd have to deploy for this relatively simple app.

So I dug into it a bit and was able to save some 25MB by restraining the language packages to English and German (yay!) using <SatelliteResourceLanguages>en;de</SatelliteResourceLanguages>, which is a step in the right direction but still way too big IMHO.

I've tried to figure out which of my packages uses up so much space and came across the dependencies included in Microsoft.Powershell.SDK, which also include Microsoft.CodeAnalysis.CSharp, which is used in the Powershell SDK tests. So far so good. But coming from a PHP background, where you can define so called dev-dependencies, I was a wondering if there was a way to remove such dependencies.

.Net supports trimming, which is great for CLI apps, because it seems to simply work, but as of today, there does not seem to be a way to do this when using Windows Forms (this is reported when building and referring to this page).

My question therefore being: is there a way, without using trimming, to remove transitive dependencies from third party packages and the Microsoft.NET.Sdk base package?

Thanks for your feedback!

Windows Forms
Windows Forms
A set of .NET Framework managed libraries for developing graphical user interfaces.
1,837 questions
.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,412 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,302 questions
{count} votes