I started learning c# a couple days ago and want to send my first program to my friend but as a standalone exe file that can be shared through google drive. I've found several solutions but I coudln't understand any of them. Is there a simple solution to compile an exe file or a standalone app in visual studio 2019 that would just work when you open it
3 Answers
One annoying thing with .NET Core is that when you build it in Visual Studio it makes lots of separate files, which is annoying for portability.
A fix to this is to right-click on your project in Solution Explorer and click Publish. Select Folder Profile, give it a name and save it.
After that, you will need to edit the target runtime option, and set it to win-x86
. After that, you should see a dropdown box at the bottom of the dialog, expand it and check 'Produce a single file'.
Then you can hit Publish and it should produce a single file.
NOTE: This does not work in .NET Framework, only .NET Core.

- 412
- 1
- 4
- 11
All you gotta do is simply build the project within Visual Studio
, once that's done. Go to your projects folder and go into bin/Release (or Debug if you've selected debug build)/myprogram.exe
. It should make a standalone .exe file!
Maybe this could also help you. Official Documentation: Compiling Building in Visual Studio

- 220
- 1
- 7
-
1this produces a couple files and an EXE file which won't function without the others and I would need to use a setup program, and that just complicates the process more. iv'e tried to share just the EXE file and it did not work, but thank you anyway. – Ron Kan Aug 15 '20 at 17:17
-
Um... so an all-in-one .exe. I know for sure I used to use that NuGet package a few months back its called Fody, once installed and loaded It will automatically be embedded into your output .exe file! https://github.com/Fody/Costura – Jessy Guirado Aug 16 '20 at 00:26
We can use dotnet publish
.Please read https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-publish.
for example:
dotnet publish -c Release -r linux-x64 --self-contained true -p:PublishSingleFile=true -p:PublishReadyToRun=true -p:PublishTrimmed=true

- 1
- 1
-
Remember that Stack Overflow isn't just intended to solve the immediate problem, but also to help future readers find solutions to similar problems, which requires understanding the underlying code. This is especially important for members of our community who are beginners, and not familiar with the syntax. Given that, **can you [edit] your answer to include an explanation of what you're doing** and why you believe it is the best approach? – Jeremy Caney Aug 11 '23 at 00:46