Defining a runtime and self-contained deployment
In the previous example, we created a console application that is operating system-agnostic. However, it had a dependency on the NETCore.App runtime. What if we want to deploy this application to a target system that doesn't have .NET Core runtime and/or SDK installed?
When the .NET Core applications need to be published, you can include the dependencies from the .NET Core framework and create a so-called self-contained package. However, by going down this path, you would need to define the target platform (operating system and CPU architecture) using a Runtime Identifier (RID) so that the .NET CLI can download the required dependencies and include them in your package.
The runtime can be defined either as part of the project file or as a parameter during publish execution:
Here, we have edited the project file to target Windows 10 with the x64 architecture. Now, if we were to publish the application (note that the publishing process is going to take place on macOS), it would create an executable for the defined target platform:
$ nano demo.csproj
$ dotnet publish
Microsoft (R) Build Engine version 15.7.179.6572 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.
Restoring packages for /demo/demo.csproj...
Installing runtime.win-x64.Microsoft.NETCore.DotNetAppHost 2.1.1.
Installing runtime.win-x64.Microsoft.NETCore.DotNetHostResolver 2.1.1.
Installing runtime.win-x64.Microsoft.NETCore.DotNetHostPolicy 2.1.1.
Installing runtime.win-x64.Microsoft.NETCore.App 2.1.1.
Generating MSBuild file /demo/obj/demo.csproj.nuget.g.props.
Generating MSBuild file /demo/obj/demo.csproj.nuget.g.targets.
Restore completed in 18.81 sec for /demo/demo.csproj.
demo -> /demo/bin/Debug/netcoreapp2.1/win10-x64/demo.dll
demo -> /demo/bin/Debug/netcoreapp2.1/win10-x64/publish/
The publish folder, in this case, would include all the necessary packages from the .NET Core runtime and framework targeting the Windows 10 runtime:
Notice that, once the deployment target platform is defined, an executable file is created and there is no more need for the driver. In fact, the executable's sole purpose here is to act as the access point (host) to the dynamic class library that is created by .NET Core.
Some of the most notable runtimes include Windows 7 to Windows 10 on three different architectures (x86, x64, and arm), multiple macOS versions, and various distributions and versions of Linux, including OpenSuse, Fedora, Debian, Ubuntu, RedHat, Tizen, and so on.