Home > News content

Use Windows Compatibility Pack to simplify migration to .NET Core

via:博客园     time:2017/12/15 23:31:52     readed:137

English original:Easing into .NET Core with the Windows Compatibility Pack

One major reason to migrate from .NET to .NET Core is the latter's ability to run on Linux. But for large-scale enterprise applications, it is impossible to achieve a one-step move in place. As a result, Microsoft recommends a gradual migration approach:

  • The first step is to migrate to ASP.NET Core (still using the .NET Framework);
  • The second step, migrate to .NET Core (still running on Windows);
  • The third step is to migrate to Linux
  • The fourth step is to migrate to Azure (hosted on a Linux host).

This approach is theoretically feasible, but in the second step there will be obstacles because of the lack of key APIs.Windows Compatibility Pack for .NET CoreThe launch, intended to solve this problem. The Compatibility Pack is a collection of NuGet packages containing nearly 20,000 APIs designed to address the needs of web application developers for great software libraries.

The newly introduced API can be roughly divided into two categories. One is the API for Windows only, and the other is a cross-platform software library. Among them, the Windows-only APIs include:

  • Active directory;
  • encryption;
  • Event log and performance counter
  • File system security
  • Named pipe
  • Registry Access
  • Windows service.

Most of these APIs are closely related to the Windows operating system, and the corresponding Linux APIs are often designed differently.

Cross-platform software libraries include:

  • Cache
  • Configuration Management (ConfigurationManager), that is, deal with legacy app.config and web.config file;
  • DatasetExtensions for accessing databases without using ORM;
  • ODBC database access
  • System.Configuration.ConfigurationManager (MEF v1);
  • System.Drawing;
  • System.IO.Packaging for interacting with MS Office-type zip files;
  • System.ServiceModel, WCF (Windows Communication Foundation).

It should be noted that these APIs are deliberately independent of the full release of .NET Core. In response, Microsoft's Immo Landwerth gives the following explanation:

The reason for being provided as a standalone package is that (a) many APIs are provided for compatibility reasons only. In the new code, should not rely on these API; (B) a lot of API only for Windows platform. We do not want to take users to a path that makes it more difficult to migrate applications across platforms.

To make it easy to distinguish between Windows-only and cross-platform APIs, there is oneAPI Compatibility Analysis ToolAvailable. The tool can mark out those applications in the API should not continue to rely on.

You can use the same suppression options as deprecated APIs, but you can also choose to give suppression warnings for specific platforms. This tool is useful if you plan to only support your code on a specific set of platforms, such as Windows and Linux only but not macOS. To do this, you simply edit the project file and add onePlatformCompatIgnoreAttribute, and lists all the platforms to ignore in this attribute.

China IT News APP

Download China IT News APP

Please rate this news

The average score will be displayed after you score.

Post comment

Do not see clearly? Click for a new code.

User comments