This Windows Compatibility Pack provides access to APIs that were previously available only for .NET Framework. It can be used from both .NET as well as .NET Standard.
$ dotnet add package Microsoft.Windows.CompatibilityThe Microsoft.Windows.Compatibility package provides Windows-specific APIs to help you port your .NET Framework applications to .NET Core 2.0+, .NET 5+ or .NET Standard. This package offers a smoother transition for those looking to modernize their applications without losing access to familiar Windows functionalities.
To start using the Microsoft.Windows.Compatibility package, you'll first need to install it via NuGet Package Manager, Package Manager Console, or by editing your project file.
After installing the package, you can access Windows-specific APIs just like you would in a .NET Framework application. Below are some examples in both C# and VB:
using Microsoft.Win32;
class Program
{
static void Main()
{
using (RegistryKey key = Registry.CurrentUser.CreateSubKey("Software\\MyApp"))
{
key.SetValue("MySetting", "MyValue");
}
}
}
Imports Microsoft.Win32
Module Program
Sub Main()
Using key As RegistryKey = Registry.CurrentUser.CreateSubKey("Software\MyApp")
key.SetValue("MySetting", "MyValue")
End Using
End Sub
End Module
using System.IO.Ports;
class Program
{
static void Main()
{
using (SerialPort port = new SerialPort("COM1", 9600))
{
port.Open();
port.WriteLine("Hello, world!");
}
}
}
Imports System.IO.Ports
Module Program
Sub Main()
Using port As New SerialPort("COM1", 9600)
port.Open()
port.WriteLine("Hello, world!")
End Using
End Sub
End Module
For more in-depth tutorials and API references, you can check the following resources:
We value your feedback! Here are ways to get in touch with us: