如何在 Linux 上运行 .NET Core 控制台应用程序 [英] How to run a .NET Core console application on Linux

查看:78
本文介绍了如何在 Linux 上运行 .NET Core 控制台应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Visual Studio 2015 并创建了一个 .NET Core 控制台应用程序.编译后,我在 debug 文件夹中有我的项目 DLL 文件.如果我想在另一台计算机上运行它,我必须在其上安装 .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:

  1. 将您的应用程序发布为自包含应用程序:

  1. 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屋!

    查看全文
    相关文章
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆