Running a standalone ASP.NET core application on Ubuntu

First off, I'm new to Linux, so forgive me.

I published an ASP.NET Core application as a standalone Ubuntu-oriented application. Publishing seems to be working fine. I copied the files to a pretty vanilla Ubuntu machine. Now, how do I run the application? I understand that since this is a standalone .NET Core application, I DO NOT need to download and install .NET Core. My application should contain everything that it needs.

All the tutorials seem to say that I should call $ dotnet run. However, the "dotnet" command line does not exist (is it supposed to be published in an offline folder?) Therefore, if I name it, I get the command "not found". Of course, I could download .NET Core, but does this not contradict the whole self-sufficient concept? Here is an example of the files that I copy.

enter image description here

+6
source share
2 answers

Answer

Now, how do I run the application? I understand that since this is a standalone .NET Core application, I DO NOT need to download and install .NET Core. My application should contain everything that it needs.

You're right. Run the executable file.

When you create a stand-alone application, the publication output "contains the complete set of files (both application files and all .NET Core files) needed to run your application." This includes an executable file.

Self-deployment example

Here is the result of dotnet publish -c release -r ubuntu.14.04-x64 for a simple stand-alone application. Copy the publishing directory to Ubuntu and run the executable.

C: \ MyApp \ Bin \ release \ netcoreapp1.0 \ ubuntu.14.04-x64 \ publish \

 ... libsos.so libsosplugin.so libuv.so Microsoft.CodeAnalysis.CSharp.dll Microsoft.CodeAnalysis.dll Microsoft.CodeAnalysis.VisualBasic.dll Microsoft.CSharp.dll Microsoft.VisualBasic.dll Microsoft.Win32.Primitives.dll Microsoft.Win32.Registry.dll mscorlib.dll mscorlib.ni.dll MyApp <------- On Ubuntu, run this executable MyApp.deps.json and you will see Hello World! MyApp.dll MyApp.pdb MyApp.runtimeconfig.json sosdocsunix.txt System.AppContext.dll System.Buffers.dll System.Collections.Concurrent.dll System.Collections.dll ... 

C: \ MyApp \ project.json

 { "buildOptions": { "debugType": "portable", "emitEntryPoint": true }, "dependencies": {}, "frameworks": { "netcoreapp1.0": { "dependencies": { "Microsoft.NETCore.App": "1.0.1" } } }, "runtimes": { "ubuntu.14.04-x64" : {}, "win10-x64" : {} } } 

C: \ MyApp \ Program.cs

 public class Program { public static void Main(string[] args) { System.Console.WriteLine("Hello World!"); } } 

see also

This document is different from structure-dependent and stand-alone deployment.

+8
source

It is worth noting that with .netstandard2 + the following two are required:

  • Edit the .csproj file and add a line with a list of target executables:

<PropertyGroup>

 <OutputType>Exe</OutputType> <TargetFramework>netcoreapp2.0</TargetFramework> <!-- Add this with the required runtimes --> <RuntimeIdentifiers>win10-x64;osx.10.11-x64;ubuntu.16.10-x64</RuntimeIdentifiers> 

</PropertyGroup>

  • Restore and create an application: dotnet restore && dotnet build -c release -r RUNTIME

Where RUNTIME is one of the versions listed in the csproj file.

It is important to note that you cannot do this without editing the .csproj file and calling restore dotnet, or the runtime will not be loaded from nuget, and the -r ... flag will not work.

+1
source

Source: https://habr.com/ru/post/1011667/


All Articles