在 Ubuntu 上运行独立的 ASP.NET Core 应用程序 [英] Running a self-contained ASP.NET Core application on Ubuntu

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

问题描述

我发布了一个 ASP.NET Core 应用程序作为面向 Ubuntu 的独立应用程序.发布似乎工作正常.我已经将这些文件复制到了一台非常普通的 Ubuntu 机器上.现在,我该如何运行我的应用程序?

我的理解是,因为它是一个独立的 .NET Core 应用程序,我不需要下载和安装 .NET Core 任何东西.我的应用程序应该包含它需要的一切.

所有教程似乎都说我应该调用 dotnet run.但是,dotnet"命令行不存在(它应该发布到自包含文件夹中吗??)所以如果我调用它,我会得到找不到命令".我当然可以下载 .NET Core,但这不违背整个独立的概念吗?

这是我正在复制的文件示例:

解决方案

答案

<块引用>

现在,我该如何运行我的应用程序?我的理解是,因为它是一个独立的 .NET Core 应用程序,我不需要下载和安装 .NET Core 任何东西.我的应用程序应该包含它需要的一切.

你说得对.运行可执行文件.

当您创建自包含应用程序时,发布输出包含启动应用程序所需的完整文件集(您的应用程序文件和所有 .NET Core 文件)."这包括可执行文件.

独立部署示例

这是一个简单的自包含应用程序的 dotnet publish -c release -r ubuntu.14.04-x64 的输出.将发布目录复制到 Ubuntu 并运行可执行文件.

C:MyAppin elease etcoreapp1.0ubuntu.14.04-x64publish

<代码>...libsos.solibsosplugin.solibuv.soMicrosoft.CodeAnalysis.CSharp.dll微软代码分析文件Microsoft.CodeAnalysis.VisualBasic.dll微软CSharp文件微软VisualBasic.dllMicrosoft.Win32.Primitives.dllMicrosoft.Win32.Registry.dllmscorlib.dllmscorlib.ni.dllMyApp <------- 在 Ubuntu 上,运行这个可执行文件MyApp.deps.json,你会看到Hello World!我的应用程序我的应用程序MyApp.runtimeconfig.jsonsosdocsunix.txtSystem.AppContext.dll系统缓冲区文件System.Collections.Concurrent.dll系统集合.dll...

C:MyAppproject.json

<代码>{构建选项":{"debugType": "便携",emitEntryPoint":真},依赖关系":{},构架": {netcoreapp1.0":{依赖关系":{"Microsoft.NETCore.App": "1.0.1"}}},运行时":{ubuntu.14.04-x64":{},win10-x64":{}}}

C:MyAppProgram.cs

公共类程序{public static void Main(string[] args){System.Console.WriteLine("Hello World!");}}

另见

本文档区分了依赖框架和独立部署.

I've published an ASP.NET Core application as a self-contained application targeting Ubuntu. The publish seems to work fine. I've copied the files to a pretty vanilla Ubuntu machine. Now, how do I run my application?

My understanding is that because it is a self-contained .NET Core application I do not need to download and install .NET Core anything. My application should contain everything it needs.

All tutorials seem to say I should call dotnet run. However, the "dotnet" command line doesn't exist (is it supposed to be published into the self-contained folder??) So if I call it, I get "command not found". Of course I could download .NET Core, but doesn't that go against the whole self-contained concept?

Here is a sample of the files I'm copying over:

解决方案

Answer

Now, how do I run my application? My understanding is that because it is a self-contained .NET Core application I do not need to download and install .NET Core anything. My application should contain everything it needs.

You are correct. Run the executable.

When you create a self-contained app, the publish output "contains the complete set of files (both your app files and all .NET Core files) needed to launch your app." That includes the executable.

Example Self-Contained Deployment

Here is the output of dotnet publish -c release -r ubuntu.14.04-x64 for a simple self-contained application. Copy the publish directory to Ubuntu and run the executable.

C:MyAppin elease etcoreapp1.0ubuntu.14.04-x64publish

...

libsos.so
libsosplugin.so
libuv.so
Microsoft.CodeAnalysis.CSharp.dll
Microsoft.CodeAnalysis.dll
Microsoft.CodeAnalysis.VisualBasic.dll
Microsoft.CSharp.dll
Microsoft.VisualBasic.dll
Microsoft.Win32.Primitives.dll
Microsoft.Win32.Registry.dll
mscorlib.dll
mscorlib.ni.dll
MyApp                        <------- On Ubuntu, run this executable
MyApp.deps.json                       and you will see Hello World!
MyApp.dll
MyApp.pdb
MyApp.runtimeconfig.json
sosdocsunix.txt
System.AppContext.dll
System.Buffers.dll
System.Collections.Concurrent.dll
System.Collections.dll

...

C:MyAppproject.json

{
  "buildOptions": {
    "debugType": "portable",
    "emitEntryPoint": true
  },
  "dependencies": {},
  "frameworks": {
    "netcoreapp1.0": {
      "dependencies": {
        "Microsoft.NETCore.App": "1.0.1"
      }
    }
  },
  "runtimes": {
    "ubuntu.14.04-x64" : {},
    "win10-x64" : {}
  }
}

C:MyAppProgram.cs

public class Program
{
    public static void Main(string[] args)
    {
        System.Console.WriteLine("Hello World!");
    }
}

See Also

This document differentiates between framework-dependent and self-contained deployments.

这篇关于在 Ubuntu 上运行独立的 ASP.NET Core 应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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