C
C#15mo 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
dukOP15mo ago
this is how my published output looks like and if i run it, it wont start
duk
dukOP15mo ago
but if i run it like this, it will start
Pobiega
Pobiega15mo 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
dukOP15mo ago
Pobiega
Pobiega15mo ago
Ok, so self-contained means it bundles the runtime X86 is a curious target thou
duk
dukOP15mo ago
i left that one on default should i change
Pobiega
Pobiega15mo ago
Ok
duk
dukOP15mo ago
win-x64
Pobiega
Pobiega15mo ago
Give it a try with x64, see if it helps But that setting is why it's a 150mb executable
duk
dukOP15mo ago
i get this in the target location
duk
dukOP15mo ago
but again the file is way to big i dont see why and it doesnt run
Pobiega
Pobiega15mo ago
Because it contains the entire runtime Why it doesn't run I don't know thou
duk
dukOP15mo ago
what do you mean the entire runtime all the packages i added and stuff
Pobiega
Pobiega15mo ago
I mean the entire .net runtime.
duk
dukOP15mo ago
do i need that
Pobiega
Pobiega15mo ago
I already answered that in my 2nd message
MODiX
MODiX15mo 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
dukOP15mo 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
Pobiega15mo ago
Well you can opt to not include it But then the user needs to install it before running your program
duk
dukOP15mo ago
yeah thats what i want i assume everyone has that already
Pobiega
Pobiega15mo ago
Ok, don't run "self-contained" then
duk
dukOP15mo ago
alright that seemed to do it
duk
dukOP15mo ago
duk
dukOP15mo 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
Pobiega15mo ago
Try running it from a command line Maybe you get some output thwre
duk
dukOP15mo ago
nothing :\
Pobiega
Pobiega15mo ago
Try this <PropertyGroup> <IncludeSymbolsInSingleFile>true</IncludeSymbolsInSingleFile> </PropertyGroup> In your csproj file I found one related GitHub issue where this worked
duk
dukOP15mo ago
got a output error because of it i assume
duk
dukOP15mo ago
duk
dukOP15mo ago
oh nvm im blind theres already a group for it it throws an error still when publishing
duk
dukOP15mo ago
duk
dukOP15mo ago
alright i published again and a bunch more files came and it ran nice
duk
dukOP15mo ago
are all of these needed or is there a better way to conceal/delete the clutter?
duk
dukOP15mo ago
i have no idea what some of these dlls are but somehow they are there
Pobiega
Pobiega15mo ago
They are all needed. There might be a way to bundle them too <DebugType>embedded</DebugType> And IncludeAllContentForSelfExtract
duk
dukOP15mo ago
in propertygroup right?
duk
dukOP15mo ago
duk
dukOP15mo ago
didnt change anything
Pobiega
Pobiega15mo ago
clean the folder before publishing again
duk
dukOP15mo 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
Pobiega15mo ago
works for me
Pobiega
Pobiega15mo ago
Pobiega
Pobiega15mo 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
dukOP15mo ago
hm weird im not unsing self contained though maybe that?
Pobiega
Pobiega15mo ago
okay, I'll disable it ok then I need to also set compression to false 😄
duk
dukOP15mo ago
im adding that to mine to see if its that
Pobiega
Pobiega15mo ago
Pobiega
Pobiega15mo 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
dukOP15mo ago
how does it not work how do you publish ur project
Pobiega
Pobiega15mo 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
dukOP15mo ago
i do that where the csproj is right
Pobiega
Pobiega15mo ago
ya
duk
dukOP15mo ago
im publishing in the visual studio gui ima try that
Pobiega
Pobiega15mo ago
yeah try not using the gui. cli is king
duk
dukOP15mo ago
can i specify the folder where i want it
Pobiega
Pobiega15mo ago
yes, -o
duk
dukOP15mo ago
sent it to C: by mistake anyways the folder is even bigger very weird
Pobiega
Pobiega15mo ago
try going to .net 7 maybe?
duk
dukOP15mo ago
Pobiega
Pobiega15mo ago
iirc it had a lot of single-file improvements in both 7 and 8
duk
dukOP15mo ago
like this right
duk
dukOP15mo ago
:\ still big
Pobiega
Pobiega15mo ago
uhm
duk
dukOP15mo ago
think it doesnt like me
Pobiega
Pobiega15mo 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
dukOP15mo ago
i changed the to 7.0 in visual studio thats the stuff it automatically changed for me
Pobiega
Pobiega15mo ago
you NEED * PublishSingleFile * RuntimeIdentifier * SelfContained = false must have all three, or this wont work
duk
dukOP15mo ago
Pobiega
Pobiega15mo ago
check the "publish" folder
duk
dukOP15mo ago
ah legend 1 exe doesnt run though damn
Pobiega
Pobiega15mo ago
idk what to say lol, it works for me :d
duk
dukOP15mo ago
damn publishing stuff is harder then programming i dont see why it doesnt run
Pobiega
Pobiega15mo ago
it kinda is, for real 🙂
duk
dukOP15mo ago
it runs when i have it in visual studio debugging
Pobiega
Pobiega15mo ago
yeah I trust you on that
duk
dukOP15mo ago
this one also runs which i assume is the debugging one
duk
dukOP15mo ago
and the one that gets used to make the single exe file when i publish
Pobiega
Pobiega15mo ago
is your code on github somewhere?
duk
dukOP15mo ago
no but i can send you the zip
Pobiega
Pobiega15mo ago
no zips thank you
duk
dukOP15mo ago
i can try to put it on github
duk
dukOP15mo ago
GitHub
GitHub - dukkk/YoutubePlaylistDownloader
Contribute to dukkk/YoutubePlaylistDownloader development by creating an account on GitHub.
Pobiega
Pobiega15mo ago
agh my dude, you forgot the .gitignore
duk
dukOP15mo ago
no idea what that is
Pobiega
Pobiega15mo ago
dotnet new gitignore in your root folder check that in, remove the .vs and obj folders from git and push
duk
dukOP15mo 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
Pobiega15mo ago
I have a few questions. Like, why does EntityFramework dlls get downloaded lol not EF Core either, oldschool EF 6
duk
dukOP15mo ago
i have no idea
Pobiega
Pobiega15mo ago
oh, because System.Data.Sqlite loads it? O_O
duk
dukOP15mo 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
Pobiega15mo ago
I'd highly recommend using Microsoft.Data.Sqlite instead
duk
dukOP15mo 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
Pobiega15mo ago
yep
duk
dukOP15mo ago
cuz you only import namespaces to be able to use their classes righ ok yeah
Pobiega
Pobiega15mo ago
in fact, VS should show you what usings can be safely removed
duk
dukOP15mo 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
Pobiega15mo ago
yes possibly at least
duk
dukOP15mo ago
found anything on the whole not running thing? cuz im lost
Pobiega
Pobiega15mo ago
its repeatable meaning, I get the same problem same error on net8
duk
dukOP15mo ago
ok theres a bunch of unhandled exceptions
Pobiega
Pobiega15mo ago
you have a bunch of warnings, but thats not the issue
duk
dukOP15mo 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
Pobiega15mo ago
there we go.
duk
dukOP15mo ago
can i not do this
duk
dukOP15mo ago
and then i start the connection with that string on frm load event
Pobiega
Pobiega15mo ago
... no wtf is that even lol why are you creating a blank connection?
duk
dukOP15mo ago
its not blank the con is blank then it uses that connectingstring to start the con but only on frmload
duk
dukOP15mo ago
duk
dukOP15mo ago
well i guess it is empty
Pobiega
Pobiega15mo ago
yeah but that still means theres a time before formload
duk
dukOP15mo ago
at the begingn
Pobiega
Pobiega15mo ago
where you are doing new sqliteconn() fixing that fixed the issue btw it now starts :p
duk
dukOP15mo 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
Pobiega15mo 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
dukOP15mo ago
ill probably delete the whole github thing later
Pobiega
Pobiega15mo ago
I changed a lot of stuff thou
duk
dukOP15mo ago
dont know whats a pull either oh how do i see it
Pobiega
Pobiega15mo ago
1 sec
duk
dukOP15mo ago
just to understand my error
duk
dukOP15mo ago
if i do it this way it will work then i con.Open(); on frmload
Pobiega
Pobiega15mo 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
Pobiega15mo 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
dukOP15mo ago
is it just me or some of the logic was changed or i cant read the whole file diff thing on github
Pobiega
Pobiega15mo 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
dukOP15mo ago
duk
dukOP15mo ago
they flipped right
Pobiega
Pobiega15mo ago
beauty of git is that you can always revert to what it was before
duk
dukOP15mo ago
i didnt do anything with git dont quite understand it all yet 😆
Pobiega
Pobiega15mo 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
dukOP15mo ago
i still didnt understand that one i use a connstring to initialize a connection
Pobiega
Pobiega15mo 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
dukOP15mo ago
how do i apply the changes you made do the github thing
Pobiega
Pobiega15mo 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
dukOP15mo ago
thanks dude i merged
Pobiega
Pobiega15mo ago
yw
duk
dukOP15mo ago
also the whole await thing i read a bunch as i had never used it i see that you added one
Pobiega
Pobiega15mo ago
oh yeah, I added an await somewhere :p rider screamed at me
duk
dukOP15mo ago
do i put it in every async method
Pobiega
Pobiega15mo ago
and the method was already async, so I figured why not pretty much, yes
duk
dukOP15mo ago
i didnt put it in the first because there was none running before that one
Pobiega
Pobiega15mo ago
at least until you understand it more
duk
dukOP15mo ago
i assumed i only needed if there was a async method already running
Pobiega
Pobiega15mo ago
no, thats not how it works
duk
dukOP15mo ago
and in this case i do want it to wait before finishing the one before oh
Pobiega
Pobiega15mo 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
dukOP15mo ago
await DownloadScheduledPlaylists(); this one could take long though and it is to be expected cuz some playlists might be huge
Pobiega
Pobiega15mo ago
sure but it also must be
Accord
Accord15mo 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