Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows Forms Single-File Executable

I am developing a Windows Forms project in Visual Studio 2019. My question is that when compiling the project, multiple files are generated, on which the executable is dependent. Is there a way to compile them all into a single .exe file? NOTE: I don't intend to use setup.exe: I just want a single executable that I can run from any part of my file system.

Thanks in advance.


2 Answers

Here are the steps to publish a single file Winforms (.NET 7.0) app (Release mode) in VS2022:

Right click on project node -> "Publish..." and press "Show all settings" link

enter image description here

Choose your target runtime, I use Win-x64 in Release mode. Open "File Publish Options" and make sure "Produce single file" option is checked.

Close the "Show all settings" dialog and press publish.

Voila!

enter image description here

like image 184
Yiannis Leoussis Avatar answered Jul 17 '26 14:07

Yiannis Leoussis


I was having the same problem, I was using .Net Framework 4.7.2, and this was the only solution I found:

Just follow these steps:

  1. Goto Manage NuGet Packages right clicking on your project.
  2. Install Costura.Fody
  3. Clean Debug folder inside the bin folder(Delete all files and folder).
  4. Run the project.
  5. Goto debug folder, then to app.publish folder, you will get a single exe file here
like image 37
Gustavo Dassie Avatar answered Jul 17 '26 13:07

Gustavo Dassie



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!