5

I'm trying to compile and run my first cross-platform app using .net core to migrate a c# 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.

8
  • "I get folders for each of these", what folder is this? Is this the publish folder or the other one? Commented Mar 8, 2018 at 18:13
  • Try to build from visual studio, copy bin\Release\netcoreapp2.0 folder to Linux, and run your app with dotnet program.dll command. Also see this issue, could be relevant: github.com/dotnet/cli/issues/7543 Commented Mar 8, 2018 at 18:24
  • @soonts I'll try that. Commented Mar 8, 2018 at 18:25
  • @omajid bin\Release\netcoreapp2.0\linux-x64 and bin\Release\netcoreapp2.0\debian-x64 respectively Commented Mar 8, 2018 at 18:25
  • Use the publish folder: bin\Release\netcoreapp2.0\linux-x64\publish instead. That is where the output of dotnet publish goes. Commented Mar 8, 2018 at 18:34

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

Comments

0

@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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.