将 .Net 核心控制台应用程序部署到 Debian 服务器 [英] Deploying .Net core console application to Debian server
问题描述
我在将简单的 .Net 核心控制台应用程序部署到 linux 服务器时遇到了一些问题.
I have some problem with deploy simple .Net core console application to linux server.
我以这种方式创建了简单的控制台 Hello world 应用程序:
I've created simple console Hello world application this way:
dotnet new console -o hello
然后我在我的 devlop 计算机上测试了这个应用程序
Then I tested this application on my devlop computer
dotnet run
效果很好.
接下来我通过这种方式创建了 debian 平台的发布
Next I created release to debian platform this way
dotnet publish -c release -r debian.8-x64 --self-contained
现在我有一个分发文件夹
Now I have a folder with distribution
C:ProjectsC#helloinMCD
elease
etcoreapp2.0debian.8-x64
我进一步将文件夹 debian.8-x64 复制到我的带有 Debias 8 操作系统的 linux 计算机
Further I took folder debian.8-x64 and copied to my linux computer with Debias 8 OS
找到要执行的文件(~/debian.8-x64/hello
)并改变它的模式
Found file for execution (~/debian.8-x64/hello
) and changed it mode
chmod +x ./hello
现在我正在尝试执行文件
Now I'm trying to execute file
./hello
出现异常
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'
Net framework 安装在与我的开发计算机上相同版本的 Linux 机器上
Net framework is installed on Linux machime with the same version as on my develop computer
root@my2ndbox:/home/alex/temp/debian.8-x64# dotnet --version
2.0.2
什么可能导致这种类型的错误?
What may cause this type of error?
推荐答案
您复制了错误的部署内容.当您dotnet 发布
时,您应该使用publish
目录的内容.对于您的情况,它应该是 release/netcoreapp2.0/debian.8-x64/publish/
.
You are copying the wrong stuff for deployment. When you dotnet publish
, you should use the contents of the publish
dir. For your case, it should be release/netcoreapp2.0/debian.8-x64/publish/
.
如果你使用非发布目录(release/netcoreapp2.0/debian.8-x64/
),它会假设你想在开发模式下运行你的项目,并希望使用来自本地 nuget 缓存的资产,这些资产很可能会在您的部署机器上丢失.
If you use the non-publish directory (release/netcoreapp2.0/debian.8-x64/
), it will assume you want to run your project in development mode, and expects to use assets from the local nuget cache, which will most likely be missing on your deployment machine.
FWIW,你在做一些非常奇怪的事情.首先,您需要决定是否真的要使用独立部署.如果是,您甚至不需要在要部署的机器上安装 dotnet.
FWIW, you are doing a few things very strangely. First, you need to decide if you want to really use self-contained deployments or not. If you are, you dont even need dotnet installed on the machine you are trying to deploy on.
这篇关于将 .Net 核心控制台应用程序部署到 Debian 服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!