Supplementing the missing APIs in. NET core with Windows Compatibility Pack

Source: Internet
Author: User

One of the biggest problems when migrating projects to. NET core is that some of the APIs are missing compared to the. NET Framework. It is divided into two main categories:

    • Windows-exclusive APIs, such as the registry
    • Unfinished functionality, such as System.Drawing

The Microsoft.Windows.Compatibility library has greatly improved the problem. It complements most of the commonly used libraries. More than 20,000 APIs have been added, such as drawing, EventLog, WMI, Performance Counters, and Windows services, all of these commonly used libraries are better supported.

According to Ms's plan, to. NET 3.0, WinForm and WPF are also compatible with extension packs into. NET core, which is an estimate that will completely replace the. NET Framework.

However, this library actually consists of more than 10 sub-libraries, because it is an extension package, the release of the time will be published more than more than 10 DLLs, if too many DLLs published, you can also install the specific child package. I wonder if Microsoft will post a runtime installation package like ASP.

Windows exclusive API cross-platform issues

It is important to note that some of the expansion pack APIs are Windows exclusive. In the case of the registry, although. NET core provides these extended packages, it works fine on windows, but because. NET core is cross-platform, these libraries are thrown out of the ordinary on Linux or Mac because these systems do not have a registry at all and cannot be supported. To resolve this exception, the following two questions are involved.

First, how do you discover these APIs that can't be cross-platform? Microsoft offers? API Analyzer Tool can help us quickly discover these APIs.

Second, how do you deal with these APIs that cannot be cross-platform? If we need to cross-platform the program, there are generally the following methods

    • Remove : Remove these features that do not cross the platform
    • Replace : replace it with functionality that can cross-platform
    • handled separately : For Windows platforms, use exclusive APIs, and for other platforms, replace them with other alternatives.

The first two kinds of not to say, the third scenario is our most commonly used, this involves another problem: How to judge our program under which platform. The API for Runtimeinformation.isosplatform is needed here, and the simple example is as follows:

????RuntimeInformation.IsOSPlatform(OSPlatform.Windows)

Limited to space, this article describes here, if you want to further understand the Windows Compatibility Pack, you can refer to the Official document Windows Compatibility Pack.

Supplementing the missing APIs in. NET core with Windows Compatibility Pack

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.