Need help publishing a dotnet 6.0 WPF application as a single exe.
I've tried everything possible, used Costura.Fody to compress together the dlls and tried every single build option in publish.xml
42 Replies
and you tried the built in CLI thing first, right?
$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.
Single file publishing | Runtime Identifier (RID) catalog | dotnet publish
yep already tried that, I'm using the mongoDB c# Driver for my project and newtonsoft json for deserializing. These dependencies for some reason don't pack into the same exe and are still standalone even after trying to publish single File as true.
Unrelated to your problem, but I'm a bit worried about the concept of packaging a WPF client with a mongo connector in it. That means you likely have a connectionstring somewhere in your app too.
I do yes, I was trying to find a way to not use the connection string but everywhere on the mongoDb c# document it only reffered to using the connection string as a way of connecting to atlas. I'm a bit of a noob so pls excuse me if im doing something wrong, I'd appreciate the help
lets get back to that later
sure
I just made a .net 6 WPF app with mongo driver and newtonsoft and published it as single file
worked fine, except the native dlls
is there a way to pack those dlls into a single exe like we were able to in .net framework 4.7.2?
yep
I literally just followed the instructions I linked above
I'll try again one sec
here is my csproj
and this is the command I ran
dotnet publish -c Release -p:IncludeNativeLibrariesForSelfExtract=true
thats all I didthe includenativelibraries for self extract, extracts the libraries to temp right?
not sure exactly where they end up when the program is run tbh
but it works
š
okay, so I did what you said with just publishing as a single file in the release directory, and I got this. My application is supposed to have an image right there but it doesn't render for some reason
should look like this
how is the image stored?
you can and should be embedding that image if you want a "proper" singlefile.
the build type of the images is content and output to directory set to always
but look at your file-sizes
thats NOT a self-contained singlefile executable
I didn't do self contained, do you recommed self contained for applications?
open up your terminal of choice and go to your project root directory
alrighty
if you want the true single-file experience, yes
oh then yes
if you dont self-contain it, then it needs .net 6 installed on the computer
yeah, definitely want self contained then
gimme a min
you have ~3, then Im going for lunch š
its important that the command is run from the project root (in my case
C:\code\temp\WpfAppPublish\WpfAppPublish\
)alright there we go
Here's my csproj
right
your images are all "copy to output"
you should investigate how to embed them as resources instead
alright I will do that
I'm not a GUI dude, so can't help, but that would mean your images get baked into the exe file
and you wont have path issues š
tysm for your help, you were more helpful than all MSDN docs combined
also btw, win-x86 is kinda pointless now
its like 0.01% of the windows userbase
yeah i was just debugging
š
time for lunch
good luck
alright
have a great lunch
thank you for the help