. NET Core application types (Portable apps & Self-contained apps) and portableapps

Source: Internet
Author: User
Tags dotnet portableapps

. NET Core application types (Portable apps & Self-contained apps) and portableapps

Introduction

There are many ways to consider the type of building an application. Generally, the type is used to describe a specific execution model or an application based on this. For example, Console applications and Web applications. All these types of applications can be created using. NET Core .. NET Core is a general development platform. However, to grant. NET Core cross-platform features,. NET Core still needs an angle to explore application types. This is called application's portablility ). Portability essentially means where your application can run and what prerequisites must be met to run on a specific machine. The following describes the portable types of the two main. NET Core types.

Portable applications

The portable application is the default application type of. NET Core. This requires. NET Core to be installed on the target machine where the program runs. This means that as a developer, your program is portable between different. NET Core devices. This type of application only needs to carry and deploy its own code and dependencies (out of the. NET Core library ). To create a portable application, all you need to do is set the current. NET Core class library in project. json, and then change frameworks to the following:

"dependencies": { "Microsoft.NETCore.App": {   "version": "1.0.0",  "type": "platform" }},"frameworks": { "netcoreapp1.0": {}}

Microsoft. NETCore. App is a "Metadata Package" that shows you your target. NET Core class library. The "type: platform" attribute in the dependency indicates that when the dependency is released, the publishing tool will omit the dependency. NET Core class library file, because these dependent class library files have already followed.. NET Core is installed on the target server.

Native dependent applications can be transplanted

The native-dependent portable application is a subset of the previously portable application. These portable applications have some native dependencies specified in specific places on the dependency chain, so that these native dependencies can be directly run on the target platform, our portable programs can also run directly on these platforms. The most typical example is our Kestrel server (ASP. NET cross-platform Web Server), which is built based on libuv (native dependency ). When you publish a portable application with native dependency, all the published output is consistent with the above. As for native dependency, the published output generates a folder for each RID (Runtime Identifier. The following project. json file shows how to use native dependencies for a portable application:

"dependencies": { "Microsoft.NETCore.App": {   "version": "1.0.0",  "type": "platform" }, "Microsoft.AspNetCore.Server.Kestrel": "1.0.0-*"},"frameworks": { "netcoreapp1.0": {}}

Self-contained applications

Unlike portable applications, independent applications do not rely on any shared components on the target machine on which you are preparing to deploy the program. Like its name implies, it means that the entire dependency is closed-loop and will be released along with the entire program at runtime. This will increase the entire release package, but it also allows the program to run in any one with the correct native dependency.. NET Core supported platforms (no need to worry about.. NET Core has been installed on the target server beforehand ). This makes it easier to deploy your application on the target server. Because the application is currently running on its own, you must specify the platform on which your program will run in advance. For example, if you want to release an independent program to Windows 10 but are not prepared to run it to macOS or Linux, you must add or delete some platforms (platforms) during development ). There are many steps to complete an independent program, but the first step is to delete any"Type": "platform"

Attribute. Step 2: KeepMicrosoft. NETCore. AppIt will pull some of the remaining things we need. Finally, we need to add a runtimes node in project. json to indicate on which platforms our program will run.

"dependencies": { "Microsoft.NETCore.App": "1.0.0"},"frameworks": { "netcoreapp1.0": {}},"runtimes": { "win10-x64": {}, "osx.10.11-x64": {}}

When we restore a project, if the project. json contains the runtimes node, NuGet will restore all the specified runtime. Next, when you need to publish an application for a given platform, use the following command line:

Dotnet publish -- runtime <RID>

The RID must be the RID specified in project. json, such as the win10-x64 or osx.10.11-x64; otherwise, an error is reported. If the operating system to be released is the operating system in which your current. NET Core is running, run the following command:

Dotnet publish

However, you still need to specify the corresponding RID in project. json.

However, note that: In. NET Core Tools Preview 2 within the time period, independent applications are released from the NuGet cache of the local machine, which means that all the dependencies of the application include.. NET Core runtime and class library are not optimized. Therefore, the performance of an independent application is lower than that of a portable application because the portable application depends on.. NET Core runtime and class library can be run at any time (ready-to-run.

The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.