Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Build .NET Core console application to output an EXE

Tags:

.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

like image 822
kenchilada Avatar asked May 19 '17 15:05

kenchilada


People also ask

How do I run a .NET core console app on Windows?

You can do it right in Visual Studio. Right click the Console App Project and select Publish. Then change Deployment Mode to Self-contained or Framework dependent. . NET Core 3.0 introduces a Single file deployment which is a single executable.

Can we create EXE for Web application?

Create EXE Executable File of Web Application in ASP.Net 3)Open the project folder and then bin folder, they you will find the exe.


1 Answers

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 
like image 93
meziantou Avatar answered Oct 15 '22 06:10

meziantou