简体   繁体   English

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

[英]Deploying .Net core console application to Debian server

I have some problem with deploy simple .Net core console application to linux server. 我在将简单的.Net核心控制台应用程序部署到linux服务器时遇到一些问题。

I've created simple console Hello world application this way: 我已经通过以下方式创建了简单的控制台Hello World应用程序:

dotnet new console -o hello

Then I tested this application on my devlop computer 然后我在devlop计算机上测试了此应用程序

dotnet run

It works fine. 工作正常。

Next I created release to debian platform this way 接下来,我以这种方式创建了到debian平台的发行版

dotnet publish -c release -r debian.8-x64 --self-contained

Now I have a folder with distribution 现在我有一个分发文件夹

C:\Projects\C#\hello\bin\MCD\release\netcoreapp2.0\debian.8-x64

Further I took folder debian.8-x64 and copied to my linux computer with Debias 8 OS 此外,我带了文件夹debian.8-x64并使用Debias 8 OS复制到了我的Linux计算机上

Found file for execution ( ~/debian.8-x64/hello ) and changed it mode 找到要执行的文件( ~/debian.8-x64/hello )并将其更改为模式

chmod +x ./hello

Now I'm trying to execute file 现在我正在尝试执行文件

./hello 

And got an exception 而且有一个例外

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 is installed on Linux machime with the same version as on my develop computer Net框架安装在Linux机器上,其版本与我的开发计算机上的版本相同

root@my2ndbox:/home/alex/temp/debian.8-x64# dotnet --version
2.0.2

What may cause this type of error? 是什么原因导致这种类型的错误?

You are copying the wrong stuff for deployment. 您正在复制错误的内容以进行部署。 When you dotnet publish , you should use the contents of the publish dir. dotnet publish ,应使用publish目录的内容。 For your case, it should be release/netcoreapp2.0/debian.8-x64/publish/ . 对于您的情况,应为release/netcoreapp2.0/debian.8-x64/publish/

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. 如果您使用非发布目录( release/netcoreapp2.0/debian.8-x64/ ),它将假定您要在开发模式下运行项目,并期望使用本地nuget缓存中的资产,这将在大多数情况下可能在您的部署计算机上丢失了。

FWIW, you are doing a few things very strangely. FWIW,您做的一些事情很奇怪。 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. 如果是这样,您甚至不需要在要进行部署的计算机上安装dotnet。

You may want to check out dotnet-packaging as well. 您可能还想检查一下dotnet-packaging It includes a dotnet deb command line utility which allows you to create a .deb file (ie a Debian installer) which you can use to install your app on Debian. 它包含一个dotnet deb命令行实用程序,可让您创建一个.deb文件(即Debian安装程序),您可以使用该文件在Debian上安装您的应用程序。 It should make deployment easier for you. 它应该使您的部署更容易。

To get started, you'll first need to add this section to your .csproj file: 首先,您首先需要将此部分添加到.csproj文件中:

<ItemGroup>
  <PackageReference Include="Packaging.Targets" Version="0.1.45" />
  <DotNetCliToolReference Include="dotnet-deb" Version="0.1.45" />
<ItemGroup>

Then, run dotnet restore and dotnet deb -c Release -r debian.8-x64 -f netcoreapp2.0 . 然后,运行dotnet restoredotnet deb -c Release -r debian.8-x64 -f netcoreapp2.0 This will create a .deb file you can use to deploy your application to Debian. 这将创建一个.deb文件,您可以使用该文件将应用程序部署到Debian。

--self-contained means that you dont need to have installed .Net Core on your target machine because all of the needed components are in the release folder --self-contained意味着您不需要在目标计算机上安装.Net Core,因为所有必需的组件都在发行文件夹中

Second thing is duplicating parameters because -r debian.8-x64 setting to true --self-contained (in other words you dont need --self-contained after you set a runtime identifier) 第二件事是复制参数,因为-r debian.8-x64设置为true --self-contained (换句话说,在您设置运行时标识符后,您不需要--self-contained

Finally try dotnet restore before publish. 最后在发布之前尝试dotnet restore Then make sure you copying right thing from ./bin/[configuration]/[framework]/[runtime] ( ./bin/[configuration]/[framework]/ is for a framework-dependent deployment). 然后确保从./bin/[configuration]/[framework]/[runtime] / ./bin/[configuration]/[framework]/框架./bin/[configuration]/[framework]/[runtime] [ ./bin/[configuration]/[framework]/ ./bin/[configuration]/[framework]/[runtime]复制正确的./bin/[configuration]/[framework]/[runtime]./bin/[configuration]/[framework]/ ./bin/[configuration]/[framework]/[runtime] / ./bin/[configuration]/[framework]/框架./bin/[configuration]/[framework]/[runtime] /用于与框架相关的部署)。 You can even set output folder manually by parameter -o (for example dotnet publish -c release -r debian.8-x64 -o copyme and copy copyme to your "linux server") 您甚至可以通过参数-o手动设置输出文件夹(例如dotnet publish -c release -r debian.8-x64 -o copyme并将copyme复制到“ Linux服务器”)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM