官术网_书友最值得收藏!

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.

主站蜘蛛池模板: 旬阳县| 水富县| 定南县| 余姚市| 成武县| 姚安县| 龙江县| 鱼台县| 淮南市| 东阳市| 丰台区| 新巴尔虎右旗| 景泰县| 井陉县| 巴林左旗| 泰宁县| 河北省| 左权县| 精河县| 景泰县| 吉木乃县| 忻城县| 罗定市| 从江县| 南雄市| 和顺县| 商南县| 济宁市| 长治市| 衡山县| 望都县| 漯河市| 西昌市| 东辽县| 邛崃市| 望江县| 威远县| 灵台县| 朔州市| 怀化市| 通山县|