❔ Publishing project
Hello, I am trying to publish a WPF project with NuGet dependencies. I am trying to publish to a single executable.
I can publish it in visual studio and get a lightweight exe but it requires a few other DLLs. I can use the command line to publish to a single file but it is very large; the flag is necessary for this, but it seems to include the .NET runtume in the executable. I would like to avoid this to reduce size since i believe windows comes with the runtime already. Any ideas?
16 Replies
depends what version of the .NET runtime you're targeting
a ClickOnce installer might be a good bet
is .NET backwards compatible with older versions?
not completely, no
unfortuante
but again, depends on the version you're targeting
.NET 6.0-windows
.NET Core and .NET 5+ do not come pre-installed in Windows
oh okay
I can do ClickOnce, I would have liked to avoid using an installer but if that's the best bet i guess it can't be helped
they are available through the Windows Package Manager in Windows 10 and 11, so that doesn't necessarily mean you need to build a self-contained executable
a ClickOnce is a decent solution
alternatively, you can dive deeper into the self-contained rabbit hole
there's a lot of gains to be made for build size when you make the extra step to AoT compilation and trimming
i will look into it, thanks 👍
Sounds like you want to take a look at $singlefile
dotnet publish -c Release -r <runtime identifier> -p:PublishSingleFile=true
Use of -p:PublishSingleFile=true
implies --self-contained true
. Add --self-contained false
to publish as runtime-dependent.
-r RID
and -p:PublishSingleFile=true
can be moved to .csproj as the following properties:but to target multiple RIDs, you have to use dotnet publish
with the -r
option for each RID.
You can also add -p:IncludeNativeLibrariesForSelfExtract=true
to include native libraries (like Common Language Runtime dlls) in the output executable.
You might want to instead publish your application compiled Ahead Of Time to native code, see $nativeaot for examples.
https://docs.microsoft.com/en-us/dotnet/core/deploying/single-file
https://docs.microsoft.com/en-us/dotnet/core/rid-catalog
https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-publishCreate a single file for application deployment - .NET
Learn what single file application is and why you should consider using this application deployment model.
.NET Runtime Identifier (RID) catalog - .NET
Learn about the runtime identifier (RID) and how RIDs are used in .NET.
oh shoot, adding --self-contained=false actually worked
it's a single file and less than a megabyte
well, it works on my machine at least...
Yeah, but it will require the runtime to be installed
yeah
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.