4
votes

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?

3
It seems to be missing a library, Microsogy.CSharp.dll. It was probably not copied along. Did you look for it?xor
As far as I know, if a self-contained is used, then there is no need to have a framework on the final machine. All dll must be in you /hello dirVasek

3 Answers

4
votes

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.

2
votes

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 (i.e. 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.

-1
votes

--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")