简体   繁体   中英

Error Running .net core on Debian

I'm trying to compile and run my first cross-platform app using .net core to migrate ac# app. I am trying to run this on Debian stretch 9.3

I've run both of these commands.

dotnet build -r debian-x64
dotnet publish -c release -r debian-x64

dotnet build -r linux-x64
dotnet publish -c release -r linux-x64

I get folders for each of these, (bin\\Release\\netcoreapp2.0\\linux-x64 and bin\\Release\\netcoreapp2.0\\debian-x64 respectively) which I used SFTP to copy to my linux box. In linux, I cd into the folder and run .\\program

I get the following error while trying to use either the debian specific or generic linux compiled code.

Error:
  An assembly specified in the application dependencies manifest (nfz_core.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'

I think I may have done something wrong in my csproj file, but I can't seem to figure out what I did wrong.

Here is my .csproj file

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp2.0</TargetFramework>
    <RuntimeIdentifiers>win10-x64;debian-x64;linux-x64</RuntimeIdentifiers>
  </PropertyGroup>

</Project>

I appreciate any insight people could give.

When you run:

dotnet publish -c release -r linux-x64

You are asking this code to be published as a Self Contained Deployment . That means all of .NET Core runtime, all your dependencies and basically anything not OS-related is published along with your application. The publish command puts your build under:

bin\Release\netcoreapp2.0\linux-x64\publish

Note: This is not the same as bin\\Release\\netcoreapp2.0\\linux-x64\\ . The linux-x64 directory contains the output of dotnet build , not dotnet publish .

Once you copy over the publish directory, you can run your program directly ( ./program ) on the target OS, without needing .NET Core installed.

An alternative is to run in Framework Dependent Deployment mode. You build without -r linux-x64 in that case. You still copy over the publish directory in that case, but you must run the application as dotnet /path/to/your.dll .

TLDR: Always copy the publish directory when deploying.

@omajid's answer is helpful.

Note that if you wish to make a Framework Dependent Deployment (FDD), you must remove <RuntimeIdentifiers> / <RuntimeIdentifier> elements from your .csproj file.

Such FDDs are smaller as they don't bundle *.so and System.*.dll files, for example. For a minimal project, you will likely only have four files to deploy (three if you exclude *.pdb debug files). These deployments are portable between runtimes.

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