Ron Kan
Ron Kan

Reputation: 75

how to make a standalone exe file

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

Upvotes: 1

Views: 18086

Answers (3)

Sifung
Sifung

Reputation: 31

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

Upvotes: 0

kettle
kettle

Reputation: 460

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.

Upvotes: 3

Jessy Guirado
Jessy Guirado

Reputation: 228

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

Upvotes: 1

Related Questions