How do you create an .EXE file from a .NET Core console application?

Posted: (EET/GMT+2)

 

By default, .NET Core console apps build to a platform-neutral DLL, which you start with the command dotnet MyApp.dll. If you prefer a standalone .exe, you would publish your application as a self-contained build.

Example:

dotnet publish -c Release -r win10-x64

This creates an EXE under bin\Release\netcoreapp2.1\win10-x64\publish.

You can also specify other runtimes (linux-x64, osx-x64). The runtime identifier (-r) tells the SDK to embed the .NET Core runtime so no shared install is needed.

To reduce size, use the .NET Core 2.1 "trim unused assemblies" option:

<PropertyGroup>
  <PublishTrimmed>true</PublishTrimmed>
</PropertyGroup>

For small tools, this produces a single-folder deployment with a normal .exe you can run or distribute. You can even go further and use dotnet publish /p:PublishSingleFile=true to get a single self-contained executable. This feature is experimental, however.