C
C#2y ago
lpha3ch0

❔ Problems with using Dotnet 6 on Windows to publish to an exe format

Dotnet/C# newb here. Previously I've only done a small amount of development using the .Net Framework on Windows in Visual Studio Community where switching between publishing an exe or dll is straightforward and easy. Now I'm trying to get familiar with publishing C#/Dotnet 6 cross platform apps in Visual Studio. I've googled this and followed guides I've found and still can't get VS to output an exe. How do I do this, and does it always have to result in a huge file size, like in standalone option, without having a separate exe and dll? When I publish to Windows, I'd prefer an exe without having to bundle a dll with it, and without it being 34MB. Am I stuck with creating projects targeting .Net Framework to get what I need?
8 Replies
lpha3ch0
lpha3ch02y ago
To clarify, when I've tried publishing in the Linux command line, a standalone executable was 34MB.
jcotton42
jcotton422y ago
I haven't used VS' publishing in forever, but the default behavior of dotnet publish on the CLI is a framework-dependent deployment that is, the user must already have the runtime installed on their machine (if your app has an installer, it could just install it of course) it sounds like you may have been doing a self-contained publish, which bundles the runtime with your app there are things like trimming you can use to cut down on the deployment size, but how well they work depends on the type of app eg GUI apps don't tend to trim very well
Becquerel
Becquerel2y ago
it is possible to publish to a single-file that isn't 30mb large. you want to look up assembly trimming
Becquerel
Becquerel2y ago
Trim self-contained applications - .NET
Learn how to trim self-contained apps to reduce their size. .NET Core bundles the runtime with an app that is published self-contained and generally includes more of the runtime then is necessary.
Becquerel
Becquerel2y ago
in short add <PublishTrimmed>true</PublishTrimmed> to your csproj and i think that will do most of the heavy lifting i think a helloworld console app is 3-5mb like this
lpha3ch0
lpha3ch02y ago
Thanks for the replies!
Becquerel
Becquerel2y ago
no prob
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.