将.Net core控制台应用程序部署到Debian服务器

Ale*_*lin 6 c# debian .net-core

我在将简单的 .Net Core 控制台应用程序部署到 Linux 服务器时遇到一些问题。

我用这种方式创建了简单的控制台 Hello world 应用程序:

dotnet new console -o hello
Run Code Online (Sandbox Code Playgroud)

然后我在我的开发计算机上测试了这个应用程序

dotnet run
Run Code Online (Sandbox Code Playgroud)

效果很好。

接下来我用这种方式创建了 debian 平台的发布版本

dotnet publish -c release -r debian.8-x64 --self-contained
Run Code Online (Sandbox Code Playgroud)

现在我有一个带有分发的文件夹

C:\Projects\C#\hello\bin\MCD\release\netcoreapp2.0\debian.8-x64
Run Code Online (Sandbox Code Playgroud)

此外,我将文件夹 debian.8-x64 复制到装有 Debian 8 操作系统的 Linux 计算机上

找到要执行的文件 ( ~/debian.8-x64/hello) 并更改其模式

chmod +x ./hello
Run Code Online (Sandbox Code Playgroud)

现在我正在尝试执行文件

./hello 
Run Code Online (Sandbox Code Playgroud)

并得到了一个例外

root@my2ndbox:/home/alex/temp/debian.8-x64# ./hello
Error:
  An assembly specified in the application dependencies manifest (hello.deps.json) was not found:
    package: 'runtime.linux-x64.Microsoft.NETCore.App', version: '2.0.0'
    path: 'runtimes/linux-x64/lib/netcoreapp2.0/Microsoft.CSharp.dll'
Run Code Online (Sandbox Code Playgroud)

Net Framework安装在Linux机器上,与我的开发计算机上的版本相同

root@my2ndbox:/home/alex/temp/debian.8-x64# dotnet --version
2.0.2
Run Code Online (Sandbox Code Playgroud)

什么可能导致此类错误?

Oma*_*jid 5

您复制了错误的部署内容。当你dotnet publish,你应该使用目录的内容publish。对于你的情况,应该是release/netcoreapp2.0/debian.8-x64/publish/

如果您使用非发布目录 ( release/netcoreapp2.0/debian.8-x64/),它将假定您希望在开发模式下运行项目,并期望使用本地 nuget 缓存中的资源,而您的部署计算机上很可能会丢失这些资源。

FWIW,你做了一些非常奇怪的事情。首先,您需要决定是否要真正使用独立部署。如果是,您甚至不需要在尝试部署的计算机上安装 dotnet。