Yes, you read it right! It's totally possible! Even .NET Core is designed to be cross platform, but it does not mean you can not use platform specific APIs. Take Windows Registry for example, although .NET Standard can not contain Windows API like this. But there's still a way to use Windows Regisitry in .NET Core Applications.

But first, you should be absolutely clear, that using platform specific APIs like Windows Regisitry will make your App or that part of code Windows only. Let's see how can we use read and write Windows Registry in .NET Core.


The API for Windows Registry is contained in package: Microsoft.Win32.Registry. It is a part of the Windows Compatibility Pack, which is designed to help developers to port their old .NET Framework applications to .NET Core piece by piece.

Add this package to your .NET Core Application:

dotnet add package Microsoft.Win32.Registry

This contains types as:


and add the namespace into your code:

using Microsoft.Win32;
Write Registry

I choose HKEY_CURRENT_USER to do this demo, because it does not require administrator privilege to access.

using (RegistryKey key = Registry.CurrentUser.CreateSubKey(@"SOFTWARE\edi_wang"))
    key.SetValue("Title", $".NET Core Rocks! {DateTime.UtcNow:MM/dd/yyyy-HHmmss}");

This will create a key "edi_wang" under HKEY_CURRENT_USER\Software, and create a string named "Title" with value like ".NET Core Rocks! 03/04/2019-073320"

Read Registry

To read this value from registry:

using (RegistryKey key = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\edi_wang"))
    if (key != null)
        Object o = key.GetValue("Title");

And we can get:

Check Platform

We know these code only works on Windows. So in practice, when we have to access Registry in .NET Core Application. We need to check the current platform before executing the code. 

if (System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
    // Registry Code

Finally, the example code is on my GitHub: