C
C#9mo ago
duk

❔ 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
duk
duk9mo ago
this is how my published output looks like and if i run it, it wont start
duk
duk9mo ago
but if i run it like this, it will start
Pobiega
Pobiega9mo ago
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
duk
duk9mo ago
Pobiega
Pobiega9mo ago
Ok, so self-contained means it bundles the runtime X86 is a curious target thou
duk
duk9mo ago
i left that one on default should i change
Pobiega
Pobiega9mo ago
Ok
duk
duk9mo ago
win-x64
Pobiega
Pobiega9mo ago
Give it a try with x64, see if it helps But that setting is why it's a 150mb executable
duk
duk9mo ago
i get this in the target location
duk
duk9mo ago
but again the file is way to big i dont see why and it doesnt run
Pobiega
Pobiega9mo ago
Because it contains the entire runtime Why it doesn't run I don't know thou
duk
duk9mo ago
what do you mean the entire runtime all the packages i added and stuff
Pobiega
Pobiega9mo ago
I mean the entire .net runtime.
duk
duk9mo ago
do i need that
Pobiega
Pobiega9mo ago
I already answered that in my 2nd message
MODiX
MODiX9mo ago
Pobiega
.net has a runtime that's required to run the programs written in .net
Quoted by
React with ❌ to remove this embed.
duk
duk9mo ago
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 😆
Pobiega
Pobiega9mo ago
Well you can opt to not include it But then the user needs to install it before running your program
duk
duk9mo ago
yeah thats what i want i assume everyone has that already
Pobiega
Pobiega9mo ago
Ok, don't run "self-contained" then
duk
duk9mo ago
alright that seemed to do it
duk
duk9mo ago
duk
duk9mo ago
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
Pobiega
Pobiega9mo ago
Try running it from a command line Maybe you get some output thwre
duk
duk9mo ago
nothing :\
Pobiega
Pobiega9mo ago
Try this <PropertyGroup> <IncludeSymbolsInSingleFile>true</IncludeSymbolsInSingleFile> </PropertyGroup> In your csproj file I found one related GitHub issue where this worked
duk
duk9mo ago
got a output error because of it i assume
duk
duk9mo ago
duk
duk9mo ago
oh nvm im blind theres already a group for it it throws an error still when publishing
duk
duk9mo ago
duk
duk9mo ago
alright i published again and a bunch more files came and it ran nice
duk
duk9mo ago
are all of these needed or is there a better way to conceal/delete the clutter?
duk
duk9mo ago
i have no idea what some of these dlls are but somehow they are there
Pobiega
Pobiega9mo ago
They are all needed. There might be a way to bundle them too <DebugType>embedded</DebugType> And IncludeAllContentForSelfExtract
duk
duk9mo ago
in propertygroup right?
duk
duk9mo ago
duk
duk9mo ago
didnt change anything
Pobiega
Pobiega9mo ago
clean the folder before publishing again
duk
duk9mo ago
i deleted the whole release folder and even added those 2 configurations to that project publish profile xml still comes with them all
Pobiega
Pobiega9mo ago
works for me
Pobiega
Pobiega9mo ago
Pobiega
Pobiega9mo ago
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net8.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
<PublishSingleFile>true</PublishSingleFile>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<SelfContained>true</SelfContained>
<DebugType>embedded</DebugType>
<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
<EnableCompressionInSingleFile>true</EnableCompressionInSingleFile>
</PropertyGroup>

</Project>
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net8.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
<PublishSingleFile>true</PublishSingleFile>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<SelfContained>true</SelfContained>
<DebugType>embedded</DebugType>
<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
<EnableCompressionInSingleFile>true</EnableCompressionInSingleFile>
</PropertyGroup>

</Project>
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
duk
duk9mo ago
hm weird im not unsing self contained though maybe that?
Pobiega
Pobiega9mo ago
okay, I'll disable it ok then I need to also set compression to false 😄
duk
duk9mo ago
im adding that to mine to see if its that
Pobiega
Pobiega9mo ago
Pobiega
Pobiega9mo ago
works fine 🙂 and so tiny! 😄
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net8.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
<PublishSingleFile>true</PublishSingleFile>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<SelfContained>false</SelfContained>
<DebugType>embedded</DebugType>
<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
<EnableCompressionInSingleFile>false</EnableCompressionInSingleFile>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="SQLite" Version="3.13.0" />
</ItemGroup>

</Project>
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net8.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
<PublishSingleFile>true</PublishSingleFile>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<SelfContained>false</SelfContained>
<DebugType>embedded</DebugType>
<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
<EnableCompressionInSingleFile>false</EnableCompressionInSingleFile>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="SQLite" Version="3.13.0" />
</ItemGroup>

</Project>
duk
duk9mo ago
how does it not work how do you publish ur project
Pobiega
Pobiega9mo ago
dotnet publish -r win-x64 probably superflous with the runtime identifier on the command, since I also have it in the file tbh
duk
duk9mo ago
i do that where the csproj is right
Pobiega
Pobiega9mo ago
ya
duk
duk9mo ago
im publishing in the visual studio gui ima try that
Pobiega
Pobiega9mo ago
yeah try not using the gui. cli is king
duk
duk9mo ago
can i specify the folder where i want it
Pobiega
Pobiega9mo ago
yes, -o
duk
duk9mo ago
sent it to C: by mistake anyways the folder is even bigger very weird
Pobiega
Pobiega9mo ago
try going to .net 7 maybe?
duk
duk9mo ago
Pobiega
Pobiega9mo ago
iirc it had a lot of single-file improvements in both 7 and 8
duk
duk9mo ago
like this right
duk
duk9mo ago
:\ still big
Pobiega
Pobiega9mo ago
uhm
duk
duk9mo ago
think it doesnt like me
Pobiega
Pobiega9mo ago
you missed a lot of settings
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net8.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
<PublishSingleFile>true</PublishSingleFile>
<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
<DebugType>embedded</DebugType>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<SelfContained>false</SelfContained>
<EnableCompressionInSingleFile>false</EnableCompressionInSingleFile>
</PropertyGroup>
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net8.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
<PublishSingleFile>true</PublishSingleFile>
<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
<DebugType>embedded</DebugType>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<SelfContained>false</SelfContained>
<EnableCompressionInSingleFile>false</EnableCompressionInSingleFile>
</PropertyGroup>
duk
duk9mo ago
i changed the to 7.0 in visual studio thats the stuff it automatically changed for me
Pobiega
Pobiega9mo ago
you NEED * PublishSingleFile * RuntimeIdentifier * SelfContained = false must have all three, or this wont work
duk
duk9mo ago
Pobiega
Pobiega9mo ago
check the "publish" folder
duk
duk9mo ago
ah legend 1 exe doesnt run though damn
Pobiega
Pobiega9mo ago
idk what to say lol, it works for me :d
duk
duk9mo ago
damn publishing stuff is harder then programming i dont see why it doesnt run
Pobiega
Pobiega9mo ago
it kinda is, for real 🙂
duk
duk9mo ago
it runs when i have it in visual studio debugging
Pobiega
Pobiega9mo ago
yeah I trust you on that
duk
duk9mo ago
this one also runs which i assume is the debugging one
duk
duk9mo ago
and the one that gets used to make the single exe file when i publish
Pobiega
Pobiega9mo ago
is your code on github somewhere?
duk
duk9mo ago
no but i can send you the zip
Pobiega
Pobiega9mo ago
no zips thank you
duk
duk9mo ago
i can try to put it on github
duk
duk9mo ago
GitHub
GitHub - dukkk/YoutubePlaylistDownloader
Contribute to dukkk/YoutubePlaylistDownloader development by creating an account on GitHub.
Pobiega
Pobiega9mo ago
agh my dude, you forgot the .gitignore
duk
duk9mo ago
no idea what that is
Pobiega
Pobiega9mo ago
dotnet new gitignore in your root folder check that in, remove the .vs and obj folders from git and push
duk
duk9mo ago
think 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
Pobiega
Pobiega9mo ago
I have a few questions. Like, why does EntityFramework dlls get downloaded lol not EF Core either, oldschool EF 6
duk
duk9mo ago
i have no idea
Pobiega
Pobiega9mo ago
oh, because System.Data.Sqlite loads it? O_O
duk
duk9mo ago
all 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
Pobiega
Pobiega9mo ago
I'd highly recommend using Microsoft.Data.Sqlite instead
duk
duk9mo ago
im 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
Pobiega
Pobiega9mo ago
yep
duk
duk9mo ago
cuz you only import namespaces to be able to use their classes righ ok yeah
Pobiega
Pobiega9mo ago
in fact, VS should show you what usings can be safely removed
duk
duk9mo ago
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?
Pobiega
Pobiega9mo ago
yes possibly at least
duk
duk9mo ago
found anything on the whole not running thing? cuz im lost
Pobiega
Pobiega9mo ago
its repeatable meaning, I get the same problem same error on net8
duk
duk9mo ago
ok theres a bunch of unhandled exceptions
Pobiega
Pobiega9mo ago
you have a bunch of warnings, but thats not the issue
duk
duk9mo ago
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)
Pobiega
Pobiega9mo ago
there we go.
duk
duk9mo ago
can i not do this
duk
duk9mo ago
and then i start the connection with that string on frm load event
Pobiega
Pobiega9mo ago
... no wtf is that even lol why are you creating a blank connection?
duk
duk9mo ago
its not blank the con is blank then it uses that connectingstring to start the con but only on frmload
duk
duk9mo ago
duk
duk9mo ago
well i guess it is empty
Pobiega
Pobiega9mo ago
yeah but that still means theres a time before formload
duk
duk9mo ago
at the begingn
Pobiega
Pobiega9mo ago
where you are doing new sqliteconn() fixing that fixed the issue btw it now starts :p
duk
duk9mo ago
what 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
Pobiega
Pobiega9mo ago
probably some conditional inside the connection library where it checks for DEBUG hang on, I'll make a pull request to your github
duk
duk9mo ago
ill probably delete the whole github thing later
Pobiega
Pobiega9mo ago
I changed a lot of stuff thou
duk
duk9mo ago
dont know whats a pull either oh how do i see it
Pobiega
Pobiega9mo ago
1 sec
duk
duk9mo ago
just to understand my error
duk
duk9mo ago
if i do it this way it will work then i con.Open(); on frmload
Pobiega
Pobiega9mo ago
yes, probably, but you can also just leave the connection un-initialized but just hang on a sec until the PR is up
Pobiega
Pobiega9mo ago
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 ones
duk
duk9mo ago
is it just me or some of the logic was changed or i cant read the whole file diff thing on github
Pobiega
Pobiega9mo ago
since I messed with indentation in THE ENTIRE FILE the diff is a bit weird yeah I didn't mess with your logic 🙂
duk
duk9mo ago
duk
duk9mo ago
they flipped right
Pobiega
Pobiega9mo ago
beauty of git is that you can always revert to what it was before
duk
duk9mo ago
i didnt do anything with git dont quite understand it all yet 😆
Pobiega
Pobiega9mo ago
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
duk
duk9mo ago
i still didnt understand that one i use a connstring to initialize a connection
Pobiega
Pobiega9mo ago
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 instead
duk
duk9mo ago
how do i apply the changes you made do the github thing
Pobiega
Pobiega9mo ago
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 exe
duk
duk9mo ago
thanks dude i merged
Pobiega
Pobiega9mo ago
yw
duk
duk9mo ago
also the whole await thing i read a bunch as i had never used it i see that you added one
Pobiega
Pobiega9mo ago
oh yeah, I added an await somewhere :p rider screamed at me
duk
duk9mo ago
do i put it in every async method
Pobiega
Pobiega9mo ago
and the method was already async, so I figured why not pretty much, yes
duk
duk9mo ago
i didnt put it in the first because there was none running before that one
Pobiega
Pobiega9mo ago
at least until you understand it more
duk
duk9mo ago
i assumed i only needed if there was a async method already running
Pobiega
Pobiega9mo ago
no, thats not how it works
duk
duk9mo ago
and in this case i do want it to wait before finishing the one before oh
Pobiega
Pobiega9mo ago
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 finish
duk
duk9mo ago
await DownloadScheduledPlaylists(); this one could take long though and it is to be expected cuz some playlists might be huge
Pobiega
Pobiega9mo ago
sure but it also must be
Accord
Accord9mo 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.
Want results from more Discord servers?
Add your server
More Posts