95

I am using Visual Studio 2015 and created a .NET Core console application. After compiling, I have my project DLL file in the debug folder. And if I want to run it on another computer, I have to install .NET on it and then write dotnet myApp.dll in command window (CMD). But I need to run my application without any installations.

I have read that I must publish my application. I do it with the command dotnet publish -c Release. Now in folder release I have a new folder, publish, with myApp.dll and other dll-files and folder runtimes for different systems. For example, in the Ubuntu.16.04-x64 folder I have file System.Security.Cryptography.Native.OpenSsl.so. But how can I run my application without any new installations of .NET or something else?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Parusnik
  • 1,131
  • 1
  • 9
  • 9

1 Answers1

183

Follow the below steps to run your application:

  1. Publish your application as a self contained application:

    dotnet publish -c release -r ubuntu.16.04-x64 --self-contained
    
  2. Copy the publish folder to the Ubuntu machine

  3. Open the Ubuntu machine terminal (CLI) and go to the project directory

  4. Provide execute permissions:

    chmod 777 ./appname
    
  5. Execute the application

    ./appname
    
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Harit Kumar
  • 2,272
  • 2
  • 12
  • 24
  • | CrossPlatformInstaller.deps.json | CrossPlatformInstaller.dll | CrossPlatformInstaller.pdb | CrossPlatformInstaller.runtimeconfig.dev.json | CrossPlatformInstaller.runtimeconfig.json | tree.txt | \---publish | CrossPlatformInstaller.deps.json | CrossPlatformInstaller.dll | CrossPlatformInstaller.pdb | CrossPlatformInstaller.runtimeconfig.json | System.AppContext.dll | ... | \---runtimes \---ubuntu.16.04-x64 \---native System.Security.Cryptography.Native.OpenSsl.so – Parusnik Oct 23 '17 at 12:35
  • that's my result folder with publish folder. Which folder I must copy to ubuntu machine? and which file I must run on ubuntu? – Parusnik Oct 23 '17 at 12:47
  • 3
    I can't execute dll-files on ubuntu – Parusnik Oct 23 '17 at 12:49
  • 2
    As i said above copy publish folder and you'll find CrossPlatformInstaller file inside that publish folder. You're checking files inside ubuntu.16.04-x64 which is not right. CrossPlatformInstaller (without extension) file is inside publish folder. – Harit Kumar Oct 23 '17 at 13:08
  • You can use this way also: [link](https://stackoverflow.com/questions/46264808/net-core-2-0-error-running-console-app-on-ubuntu?rq=1) – Harit Kumar Oct 23 '17 at 13:27
  • Should I install dotnet on ubuntu? – Parusnik Oct 23 '17 at 13:34
  • No need to install .NET Core on Ubuntu for self contained applications. Just follow the above steps. – Harit Kumar Oct 23 '17 at 13:35
  • I think, I don't understand something. I have publish folder with files: myApp.dll, myApp.pdb, myApp.deps.json, myApp.runtimeconfig.json. I copy this folder to ubunty. Then provide execute permissions: chmod 777 ./myApp.dll. Then try to execute it but can't ./myApp.dll – Parusnik Oct 23 '17 at 13:38
  • [Another link](https://stackoverflow.com/questions/40226032/running-self-contained-asp-net-core-application-on-ubuntu?rq=1) – Harit Kumar Oct 23 '17 at 13:40
  • What's inside your publish folder? If you can't find CrossPlatformInstaller file inside publish folder then application is not published properly. You've missed something. – Harit Kumar Oct 23 '17 at 13:42
  • I don't have exec file, I have only dll ((( – Parusnik Oct 23 '17 at 13:43
  • I have publish folder with files: myApp.dll, myApp.pdb, myApp.deps.json, myApp.runtimeconfig.json. – Parusnik Oct 23 '17 at 13:45
  • Make sure you've specified ubuntu.16.04-x64 also inside .csproj file PropertyGroup. – Harit Kumar Oct 23 '17 at 13:59
  • I'am using 2015 VS, and I have .xproj file. After additing RuntimeIdentifiers executable file didn't apear(( – Parusnik Oct 24 '17 at 06:48
  • I install VS 2017 and now I have all these files)) – Parusnik Oct 24 '17 at 06:56
  • @HaritKumar I have followed your process but it is not working. It will not generate .deb file. Give me some way to generate .Deb File – AbdulAzeem Jul 25 '19 at 06:07
  • Thanks for sharing solution. Its working fine on my linux server but could you tell me how to schedule this ./appname on linux server like task scheduler. I want to execute this console app every 15 minutes after 5 PM every day. – Vishal Hatiskar Jun 02 '20 at 04:22
  • How to execute the app not being in the apps folder??? "./appfolder/app" not working. – ADM-IT Sep 21 '20 at 18:24
  • Are executable names converted to lowercase when deployed on Linux? If my project output is set to `MyProgram.exe` on Windows, does it appear as `myprogram` on Linux automatically? – void.pointer Mar 10 '21 at 17:17
  • 8
    One should just chmod to the least needed permission. 777 allows anyone to read and write and execute to the file, I wouldn't recommend it... – Jefferson Quesado Aug 08 '21 at 02:45
  • I could easily be wrong, but my reading (and experiments) suggests none of this works for a 'console' application, but only for a 'core' application. For a console app it appears one needs to use mono instead. Possibly vs 2017 allowed it, with vs2019 it seems impossible. By all means correct me if I"m wrong :-) – Chris Pugmire Jan 31 '23 at 00:22