如何在Linux上运行.NET Core控制台应用程序 [英] How to run a .NET Core console application on Linux
问题描述
我正在使用Visual Studio 2015,并创建了一个.NET Core控制台应用程序。编译后,我的项目DLL文件位于 debug 文件夹中。如果要在另一台计算机上运行它,则必须在其上安装.NET,然后在命令窗口(CMD)中写入 dotnet myApp.dll
。但是我需要在不进行任何安装的情况下运行我的应用程序。
I am using Visual Studio 2015 and created a .NET Core console application. After compiling, I have my project DLL file in the debug folder. And if I want to run it on another computer, I have to install .NET on it and then write dotnet myApp.dll
in command window (CMD). But I need to run my application without any installations.
我已阅读到必须发布应用程序。我使用命令 dotnet publish -c Release
来完成。现在在文件夹 release 中,我有一个新文件夹 publish ,其中包含myApp.dll和其他dll文件以及用于不同系统的文件夹运行时。例如,在 Ubuntu.16.04-x64 文件夹中,文件为 System.Security.Cryptography.Native.OpenSsl.so 。但是,如何在没有任何新安装的.NET或其他任何东西的情况下运行我的应用程序?
I have read that I must publish my application. I do it with the command dotnet publish -c Release
. Now in folder release I have a new folder, publish, with myApp.dll and other dll-files and folder runtimes for different systems. For example, in the Ubuntu.16.04-x64 folder I have file System.Security.Cryptography.Native.OpenSsl.so. But how can I run my application without any new installations of .NET or something else?
推荐答案
请按照以下步骤运行您的应用程序应用程序:
Follow the below steps to run your application:
-
将您的应用程序发布为自包含应用程序:
Publish your application as a self contained application:
dotnet publish -c release -r ubuntu.16.04-x64 --self-contained
将 publish
文件夹复制到Ubuntu计算机上
Copy the publish
folder to the Ubuntu machine
打开Ubuntu计算机终端(CLI)并转到项目目录
Open the Ubuntu machine terminal (CLI) and go to the project directory
提供执行权限:
chmod 777 ./appname
执行应用程序
Execute the application
./appname
这篇关于如何在Linux上运行.NET Core控制台应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!