简体   繁体   中英

Deploying .Net core console application to Debian server

I have some problem with deploy simple .Net core console application to linux server.

I've created simple console Hello world application this way:

dotnet new console -o hello

Then I tested this application on my devlop computer

dotnet run

It works fine.

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:\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

Found file for execution ( ~/debian.8-x64/hello ) and changed it mode

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

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. For your case, it should be 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.

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.

You may want to check out dotnet-packaging as well. 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. It should make deployment easier for you.

To get started, you'll first need to add this section to your .csproj file:

<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 . This will create a .deb file you can use to deploy your application to 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

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)

Finally try dotnet restore before publish. Then make sure you copying right thing from ./bin/[configuration]/[framework]/[runtime] ( ./bin/[configuration]/[framework]/ is for a framework-dependent deployment). 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")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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