How to run .NET Core console app from the command line

前端 未结 7 863
-上瘾入骨i
-上瘾入骨i 2020-12-07 09:30

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

相关标签:
7条回答
  • 2020-12-07 10:09

    You can very easily create an EXE (for Windows) without using any cryptic build commands. You can do it right in Visual Studio.

    1. Right click the Console App Project and select Publish.
    2. A new page will open up (screen shot below)
    3. Hit Configure...
    4. Then change Deployment Mode to Self-contained or Framework dependent. .NET Core 3.0 introduces a Single file deployment which is a single executable.
    5. Use "framework dependent" if you know the target machine has a .NET Core runtime as it will produce fewer files to install.
    6. If you now view the bin folder in explorer, you will find the .exe file.
    7. You will have to deploy the exe along with any supporting config and dll files.

    0 讨论(0)
  • 2020-12-07 10:10

    With dotnetcore3.0 you can package entire solution into a single-file executable using PublishSingleFile property

    -p:PublishSingleFile=True
    

    Source Single-file executables

    An example of Self Contained, Release OSX executable:

    dotnet publish -c Release -r osx-x64 -p:PublishSingleFile=True --self-contained True
    

    An example of Self Contained, Debug Linux 64bit executable:

    dotnet publish -c Debug -r linux-x64 -p:PublishSingleFile=True --self-contained True
    

    Linux build is independed of distribution and I have found them working on Ubuntu 18.10, CentOS 7.7, and Amazon Linux 2.

    A Self Contained executable includes Dotnet 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, OSX and

    <ProjectDir>\bin\<Release or Debug>\netcoreapp3.0\<target-os>\publish\ on Windows.

    0 讨论(0)
  • 2020-12-07 10:16

    Go to ...\bin\Debug\net5.0 (net5.0 can also be something like "netcoreapp2.2" depending on the framework you use.)

    Open the power shell by clicking on it like shown in the picture.

    Type in powershell: .\yourApp.exe

    You don't need dotnet publish just make sure you build it before to include all changes.

    0 讨论(0)
  • 2020-12-07 10:23

    before you run in cmd prompt, make sure "appsettings.json" has same values as "appsettings.Development.json".

    In command prompt, go all the way to bin/debug/netcoreapp2.0 folder. then run "dotnet applicationname.dll"

    0 讨论(0)
  • 2020-12-07 10:29

    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 Docs.

    0 讨论(0)
  • 2020-12-07 10:30

    Using CMD you can run a console .net core project if .net core SDK is installed in your machine :

    To run console project using windows command-Line, choose the specific path from your directory and type following below command

    dotnet run

    0 讨论(0)
提交回复
热议问题