简体   繁体   中英

.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

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 aa 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

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