I have a .NET Core console application and have run dotnet publish
. However, I can't figure out how to run the application from the command line. Any hints?

- 30,738
- 21
- 105
- 131

- 15,275
- 27
- 77
- 131
-
Perhaps this can be of help: https://stackoverflow.com/questions/44074121/build-net-core-console-application-to-output-an-exe – Bent Tranberg Sep 06 '18 at 12:38
9 Answers
If it's a framework-dependent application (the default), you run it by dotnet yourapp.dll
.
If it's a self-contained application, you run it using yourapp.exe
on Windows and ./yourapp
on Unix.
For more information about the differences between the two app types, see the .NET Core Application Deployment article on .NET documentation.

- 30,738
- 21
- 105
- 131

- 236,525
- 50
- 385
- 514
-
30Its amazing how long it took me to find this out. I am trying all kinds of "dotnet run" commands, etc. This is the first place that I have come across in a lot of searching that gives the correct dotnet usage for running a console application. Why did Microsoft make .NET Core so un-developer friendly? – Glen Thomas Mar 21 '17 at 10:25
-
3@GlenThomas If you want to run an application you're developing, you use `dotnet run`. Also, where did you look? Where would you expect this information? – svick Mar 21 '17 at 12:07
-
1"dotnet run" no longer seems to be the case with .NET core projects using the newer MSBuild csproj setup rather than the old project.json files. – Glen Thomas Mar 21 '17 at 15:09
-
3@GlenThomas That's not true, [`dotnet run`](https://learn.microsoft.com/en-us/dotnet/articles/core/tools/dotnet-run) works the same for the new csproj projects as it did for project.json. – svick Mar 21 '17 at 16:30
-
I can't get it to work, I just get an error that the project.json file is not found as it does not exist. This is with .NET Core v1.1 – Glen Thomas Mar 22 '17 at 13:17
-
@GlenThomas That could mean you have global.json which makes you run an older version of the dotnet CLI. You might consider asking a question about that. – svick Mar 22 '17 at 13:32
-
-
5@GlenThomas, not sure if this is the problem you were having, but when you try to use `dotnet run`, make sure you're in the project directory, not the solution directory. – Ryan Lundy Dec 12 '18 at 09:52
-
1In the `..\bin\debug\netcoreapp2.2` folder I use the following command: `dotnet run yourapp.dll --project ..\..\..\ ` – Post Impatica Feb 18 '19 at 18:46
-
@svick How to call the console app from the command-line without always `cd-ing` to the bin folder? My `path` environment variable is too large. – Legends Jun 29 '20 at 11:50
-
So after a publish for a Hello World type app I got a folder full of dlls. How much of that do I need? To deploy that app I need the contents of the entire publish directory??? I know I need more than just the app and the related xml file. – Michael Welch Jul 24 '20 at 20:48
-
1@MichaelWelch You pretty much need all of them. Though if you want, [you can merge them all into a single file by adding `
true ` to your .csproj](https://learn.microsoft.com/en-us/dotnet/core/whats-new/dotnet-core-3-0#single-file-executables). – svick Jul 27 '20 at 11:59 -
It's odd that @GlenThomas said that it took a long time for him to find this answer. When I asked Bing "execute net core console app," this thread was the first item in the response. – David A. Gray Aug 23 '20 at 00:01
-
2
-
1I agree with @GlenThomas, it took me a while to figure out that dotnet app.dll was what I needed instead of dotnet run app.dll, just the first ideas I had in my mind that were wrong. Thanks for this answer :) . – codea Jun 05 '21 at 13:49
-
dotnet myapp.dll does not work. It says file path must be a non-empty string. The error is in program.cs file in my .net core 3.1 project. Error line is CreateHostBuilder(args).Build().Run(). – Rajeev Menon Mar 01 '23 at 15:40
You can very easily create an EXE (for Windows) without using any cryptic build commands. You can do it right in Visual Studio.
- Right click the Console App Project and select Publish.
- A new page will open up (screen shot below)
- Hit Configure...
- Then change Deployment Mode to Self-contained or Framework dependent. .NET Core 3.0 introduces a Single file deployment which is a single executable.
- Use "framework dependent" if you know the target machine has a .NET Core runtime as it will produce fewer files to install.
- If you now view the bin folder in explorer, you will find the .exe file.
- You will have to deploy the exe along with any supporting config and dll files.

- 23,901
- 21
- 124
- 145
-
6Yep. There's the EXE - along with 217 other files (api-ms-win-core-namedpipe-l1-1-0.dll, etc). Is there anyway to bundle this down to a single EXE? – Elton Jan 09 '19 at 16:35
-
1Good question @Elton. I don' know. AFAIK you have to deploy all the dlls. – Jess Jan 10 '19 at 13:15
-
2I would think the fact that it is configured to be self-contained would require all of those DLLs to be there. If you don't want them there, the deployment mode would probably need to be Framework Dependent – kippermand Feb 21 '19 at 18:51
-
1
You can also run your application like any other console applications, but only after the publish.
Let's suppose you have the simple console application named MyTestConsoleApp.
Open the package manager console and run the following command:
dotnet publish -c Debug -r win10-x64
The -c
flag mean that you want to use the debug configuration (in other case you should use Release value)
The -r
flag means that your application will be run on the Windows platform with an x64 architecture.
When the publish procedure will be finished you will see the *.exe file located in your bin/Debug/publish directory.
Now you can call it via command-line tools. So open the CMD window (or terminal) move to the directory where your *.exe file is located and write the next command:
>> MyTestConsoleApp.exe argument-list
For example:
>> MyTestConsoleApp.exe --input some_text -r true

- 30,738
- 21
- 105
- 131

- 726
- 7
- 23
With .NET Core 3.0 you can package the entire solution into a single-file executable using the PublishSingleFile
property:
-p:PublishSingleFile=True
Source: Single-file executables
An example of a self-contained, release OS X executable:
dotnet publish -c Release -r osx-x64 -p:PublishSingleFile=True --self-contained True
An example of a self-contained, debug Linux 64-bit executable:
dotnet publish -c Debug -r linux-x64 -p:PublishSingleFile=True --self-contained True
The Linux build is independent of distribution and I have found them working on Ubuntu 18.10 (Cosmic Cuttlefish), CentOS 7.7, and Amazon Linux 2.
A self-contained executable includes the .NET runtime and runtime does not require to be installed on a target machine. The published executables are saved under:
<ProjectDir>/bin/<Release or Debug>/netcoreapp3.0/<target-os>/publish/
on Linux, OS X and
<ProjectDir>\bin\<Release or Debug>\netcoreapp3.0\<target-os>\publish\
on Windows.

- 30,738
- 21
- 105
- 131

- 2,021
- 1
- 10
- 17
Using CMD you can run a console .NET Core project if .NET Core SDK is installed on your machine:
To run a console project using the Windows command-Line, choose the specific path from your directory and type the following below command:
dotnet run

- 30,738
- 21
- 105
- 131

- 320
- 1
- 2
- 14
Go to ...\bin\Debug\net5.0
("net5.0" can also be something like "netcoreapp2.2", depending on the framework you use.)
Open a PowerShell window by clicking on it like shown in the picture.
Type in the PowerShell window: .\yourApp.exe
You don't need dotnet publish
. Just make sure you build it before to include all changes.

- 30,738
- 21
- 105
- 131

- 31
- 2
Before you run in a command prompt, make sure "appsettings.json" has the same values as "appsettings.Development.json".
In a command prompt, go all the way to the bin/debug/netcoreapp2.0 folder. Then run "dotnet applicationname.dll"

- 30,738
- 21
- 105
- 131

- 41
- 2
If it's a framework-dependent application (the default), you run it by dotnet yourapp.dll.
Folder Path :- Bin\Debug\net5.0
Steps ;_
- Cd and paste path 2)run dotnet yourapp.dll.
My Application Path : C:\Projects\CallLetter\CallLetterConsoleApp\CallL etterConsoleApp\bin\Debug\net5.0

- 1
- 3
- Open a command prompt or terminal window.
- Navigate to the directory that contains the compiled executable file of your .NET Core console application. The executable file has a .exe extension.
- Use the dotnet command followed by the name of the executable file to run the application. For example, if your executable file is named "MyApp.exe", the command would be:
dotnet MyApp.exe
- Press Enter to execute the command.
- Your .NET Core console application will start running, and you will see the output in the command prompt or terminal window.
That's it! Your .NET Core console application is now running from the command line.

- 9
- 3