ca9163d9
ca9163d9

Reputation: 29209

.Net core application cannot run on Linux?

I created a .Net core C# console application in Visual Studio and used the following steps to test it on Linux.

  1. Use Visual Studio "Build -> Publish" menu item to create the executable files in ....\bin\Release\netcoreapp2.1\publish.
  2. Copy the "publish" directory to the Linux machine
  3. On Linux, chmod 777 myApp.dll
  4. ./myApp.dll

However, executing the app shows the error of

-bash: ./myApp.dll: cannot execute binary file

Upvotes: 1

Views: 7395

Answers (1)

omajid
omajid

Reputation: 15223

It looks like you did a Framework-Dependendent Deployment. Essentially, the publish command was:

dotnet publish -c Release

FDD assumes that you are going to have a .NET Core runtime to run your application on the target platform.

Once you copied over the publish directory to another machine (which could be Linux, macOS or Windows), your application still needs a .NET Core runtime to run your application.

Installing the .NET Core runtime depends on the particular Linux distribution that you are using. Once you have it installed, you can run your application by doing:

dotnet /path/to/publish/myApp.dll

An alternative to Framework Dependent Deployment is Self-Contained Deployment. In this mode, the published application will contain your application as well as a copy of the .NET Core runtime. On command line, doing a a SCD publish looks like this:

dotnet publish -r linux-x64 -c Release

For doing this in Visual Studio, see the link above. Then, you should see a bin\Release\netcoreapp2.1\linux-x64\publish\ directory that contains a myApp file. You can copy over this publish dir over to a Linux distribution and just run:

/path/to/linux-x64/publish/myApp

Upvotes: 9

Related Questions