❔ Publishing an winforms application
Im having some issues or i dont understand how publishing works, basically i wanted to compile my app as a single executable self contained exe (i assume all the dlls and other stuff all would be contained in the exe) and after doing this and running the exe alone in a folder the application doesnt start, also the exe goes from the 200kb debug exe to a 150mb published exe file.
Whats the best way to compile a application as to keep the clutter of files down while also keeping the exe file size low? Is it even possible?
149 Replies
this is how my published output looks like and if i run it, it wont start
but if i run it like this, it will start
What publish settings do you have in your csproj/passing to publish?
.net has a runtime that's required to run the programs written in .net
You can bundle this with your published exe, or expect the user to have it installed already
Ok, so self-contained means it bundles the runtime
X86 is a curious target thou
i left that one on default
should i change
Ok
win-x64
Give it a try with x64, see if it helps
But that setting is why it's a 150mb executable
i get this in the target location
but again the file is way to big i dont see why
and it doesnt run
Because it contains the entire runtime
Why it doesn't run I don't know thou
what do you mean the entire runtime
all the packages i added and stuff
I mean the entire .net runtime.
do i need that
I already answered that in my 2nd message
Pobiega
.net has a runtime that's required to run the programs written in .net
Quoted by
<@105026391237480448> from #Publishing an winforms application (click here)
React with ❌ to remove this embed.
soo whatever i do it will always be that big of a file
sorry if im being dumb
usually my projects dont leave visual studio 😆
Well you can opt to not include it
But then the user needs to install it before running your program
yeah thats what i want
i assume everyone has that already
Ok, don't run "self-contained" then
alright that seemed to do it
now i need to figure out why it doesnt run
the debug exe runs fine but when i publish it, it just doesnt run
which tells me its not even starting because if it actually started and ran
and then ran into a error i should get a messagebox with it
Try running it from a command line
Maybe you get some output thwre
nothing :\
Try this
<PropertyGroup>
<IncludeSymbolsInSingleFile>true</IncludeSymbolsInSingleFile>
</PropertyGroup>
In your csproj file
I found one related GitHub issue where this worked
got a output error because of it i assume
oh nvm
im blind
theres already a group for it
it throws an error still
when publishing
alright i published again and a bunch more files came and it ran
nice
are all of these needed or is there a better way to conceal/delete the clutter?
i have no idea what some of these dlls are
but somehow they are there
They are all needed. There might be a way to bundle them too
<DebugType>embedded</DebugType>
And
IncludeAllContentForSelfExtract
in propertygroup right?
didnt change anything
clean the folder before publishing again
i deleted the whole release folder
and even added those 2 configurations to that project publish profile xml
still comes with them all
works for me
thats my csproj
granted, its a fresh entirely empty winforms project, and I'm using .NET 8
added sqlite as a dependency, as I know that has unmanaged dlls
still works
hm weird
im not unsing self contained though
maybe that?
okay, I'll disable it
ok then I need to also set compression to false 😄
im adding that to mine to see if its that
works fine 🙂
and so tiny! 😄
how does it not work
how do you publish ur project
dotnet publish -r win-x64
probably superflous with the runtime identifier on the command, since I also have it in the file tbhi do that where the csproj is right
ya
im publishing in the visual studio gui
ima try that
yeah try not using the gui.
cli is king
can i specify the folder where i want it
yes,
-o
sent it to C: by mistake
anyways the folder is even bigger
very weird
try going to .net 7 maybe?
iirc it had a lot of single-file improvements in both 7 and 8
like this right
:\ still big
uhm
think it doesnt like me
you missed a lot of settings
i changed the to 7.0 in visual studio thats the stuff it automatically changed for me
you NEED
* PublishSingleFile
* RuntimeIdentifier
* SelfContained = false
must have all three, or this wont work
check the "publish" folder
ah
legend
1 exe
doesnt run though
damn
idk what to say lol, it works for me :d
damn publishing stuff is harder then programming
i dont see why it doesnt run
it kinda is, for real 🙂
it runs when i have it in visual studio
debugging
yeah I trust you on that
this one also runs which i assume is the debugging one
and the one that gets used to make the single exe file when i publish
is your code on github somewhere?
no but i can send you the zip
no zips thank you
i can try to put it on github
GitHub
GitHub - dukkk/YoutubePlaylistDownloader
Contribute to dukkk/YoutubePlaylistDownloader development by creating an account on GitHub.
agh my dude, you forgot the .gitignore
no idea what that is
dotnet new gitignore
in your root folder
check that in, remove the .vs
and obj
folders from git and pushthink i did it
them guis not doing it all
dont make fun of my code :(
this is just a little program that only i will probably use
youtube niche music being deleted means that i lose them forever soo i must download playlists monthly to never lose em ever again
I have a few questions. Like, why does EntityFramework dlls get downloaded lol
not EF Core either, oldschool EF 6
i have no idea
oh, because
System.Data.Sqlite
loads it? O_Oall i did was just go on nuget browser
and get the stuff i need
i think i removed everything i dont need
cuz i had some other stuff that i was going to use but then didnt
and removed it
I'd highly recommend using
Microsoft.Data.Sqlite
insteadim pretty sure theres a bunch of namespaces that im not using
yeah i generally just went with the first one that appeared
probably not recommended 😆
or whatever documents i was reading
general programming question:
if i remove a namespace from my .cs and no errors pop up its safe to assume nothing will break right
yep
cuz you only import namespaces to be able to use their classes righ
ok yeah
in fact, VS should show you what usings can be safely removed
the grey ones?
yup
soo like almost all of them
like i said alot of stuff was scraped 😆
would those namespaces being used import a .dll even if they dont require me to download a package?
yes
possibly at least
found anything on the whole not running thing?
cuz im lost
its repeatable
meaning, I get the same problem
same error on net8
ok theres a bunch of unhandled exceptions
you have a bunch of warnings, but thats not the issue
need to see why they dont pop up while im debugging
i went to windows event viewer and it logs there despite not doing on cmd when i manually execute it
Application: PlaylistDownloader.exe
CoreCLR Version: 7.0.1023.36312
.NET Version: 7.0.10
Description: The process was terminated due to an unhandled exception.
Exception Info: System.ArgumentNullException: Value cannot be null. (Parameter 'path1')
at System.ArgumentNullException.Throw(String paramName)
at System.IO.Path.Combine(String path1, String path2)
at System.Data.SQLite.SQLiteConnection..ctor(String connectionString, Boolean parseViaFramework)
at System.Data.SQLite.SQLiteConnection..ctor(String connectionString)
at System.Data.SQLite.SQLiteConnection..ctor()
at PlaylistDownloader.frmMain..ctor() in C:\Users\Uset\Desktop\Stuff Yo Kno'\Programming\C# & VB & C++\PlaylistDownloader\frmMain.cs:line 22
at PlaylistDownloader.Program.Main() in C:\Users\Uset\Desktop\Stuff Yo Kno'\Programming\C# & VB & C++\PlaylistDownloader\Program.cs:line 14
(this is the log after running the solo exe file)
there we go.
can i not do this
and then i start the connection with that string on frm load event
...
no
wtf is that even lol
why are you creating a blank connection?
its not blank
the con is blank
then it uses that connectingstring to start the con
but only on frmload
well i guess it is empty
yeah but that still means theres a time before formload
at the begingn
where you are doing
new sqliteconn()
fixing that fixed the issue btw
it now starts :pwhat did you do
and why doesnt this error occur while debugging
i can start it just fine when debugging
or when using the debug executable
soo weird
probably some conditional inside the connection library
where it checks for DEBUG
hang on, I'll make a pull request to your github
ill probably delete the whole github thing later
I changed a lot of stuff thou
dont know whats a pull either
oh
how do i see it
1 sec
just to understand my error
if i do it this way it will work
then i con.Open(); on frmload
yes, probably, but you can also just leave the connection un-initialized
but just hang on a sec until the PR is up
GitHub
fix single file issues, clean up code, fix connstr bug by pobiega ·...
publish now works as expected via dotnet publish -r win-x64 -c Release
to summarize what I did, I added a standard editorconfig file, let rider format your code and did some low-hanging-fruit cleanups, and fixed the
new();
bug
I also changed your sqlite library for a more appropriate one
that didnt bundle EF6 😄
oh, and I used the more modern file-scoped namespaces instead of the nasty block onesis it just me or some of the logic was changed
or i cant read the whole file diff thing on github
since I messed with indentation in THE ENTIRE FILE the diff is a bit weird yeah
I didn't mess with your logic 🙂
they flipped
right
beauty of git is that you can always revert to what it was before
i didnt do anything with git
dont quite understand it all yet 😆
but yeah, that diff is probably comparing different methods
see how the order also changed
can assure you I didn't touch that 😛
I changed how you initialize your connections in one or two places
since you used con instead of connstr once
i still didnt understand that one
i use a connstring to initialize a connection
in one place you didn't
you actually made a new connection from the existing one, instead of using the connstr
or maybe that was a bug from when I tried to use
Microsoft.Data.Sqlite
insteadhow do i apply the changes you made do the github thing
approve the pull request
go to the first tab, conversations
you should have a "merge" or "approve" or something button
there you go
now "git pull" locally
so you get the latest version on your computer
then publish with the command I wrote:
dotnet publish -r win-x64 -c Release
and you should get a working published single file exethanks dude
i merged
yw
also the whole await thing i read a bunch as i had never used it
i see that you added one
oh yeah, I added an
await
somewhere :p
rider screamed at medo i put it in every async method
and the method was already async, so I figured why not
pretty much, yes
i didnt put it in the first because there was none running before that one
at least until you understand it more
i assumed i only needed if there was a async method already running
no, thats not how it works
and in this case i do want it to wait before finishing the one before
oh
without
await
it will start and then carry on. so if the download is taking long, it would cause issues
now it actually waits for the download to finishawait DownloadScheduledPlaylists(); this one could take long though
and it is to be expected
cuz some playlists might be huge
sure
but it also must be
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.