Build .NET Core console application to output an EXE

.net core

For a console application project targeting .NET Core 1.0, I cannot figure out how to get an .exe to output during build. The project runs fine in debug.

I've tried publishing the project, but that does not work either. It makes sense since an EXE file would be platform-specific, but there must be a way. My searches have only turned up reference to older .NET Core versions that used project.json.

Whenever I build or publish, this is all I get:

Build directory

Best Answer

For debugging purposes, you can use the DLL file. You can run it using dotnet ConsoleApp2.dll. If you want to generate an EXE file, you have to generate a self-contained application.

To generate a self-contained application (EXE in Windows), you must specify the target runtime (which is specific to the operating system you target).

Pre-.NET Core 2.0 only: First, add the runtime identifier of the target runtimes in the .csproj file (list of supported RIDs):

<PropertyGroup>
    <RuntimeIdentifiers>win10-x64;ubuntu.16.10-x64</RuntimeIdentifiers>
</PropertyGroup>

The above step is no longer required starting with .NET Core 2.0.

Then, set the desired runtime when you publish your application:

dotnet publish -c Release -r win10-x64
dotnet publish -c Release -r ubuntu.16.10-x64