The term UWP is used for a lot of things: UI (WinUI), the Windows AppModel, Windows Runtime API, Store Apps,…  As I’m planning to keep this a short blogpost, I’m not going to discuss this here 😀 For sake of this blogpost UWP APIs== the Window Runtime API.

Just 1 NuGet package

In a previous blogpost, I talked about how I used the Windows.Devices.SmartCards.SmartCardReaderclass to access an eID and read the content from it. This demo was written in a UWP app (you know, the ‘full’/’classic’/store/modern UI/… UWP kinda app).

What few people know, is that these Windows Runtime APIs aren’t exclusive for these kinds of app. It’s possible to access these APIs from WinForms, WPF, even from the Console.

The only thing you have to do to make this work is adding a reference to the Microsoft.Windows.SDK.Contract NuGet Package. Once that package is added, we can use the Windows Runtime APIs!

Show me the money!

I created a new .NET Core Console application and added areference to the Microsoft.Windows.SDK.Contract NuGet package.

Afterwards I simply added some code that uses specific Windows Runtime APIs:

public static async Task Main(string[] args)
    Console.WriteLine("Hello World!");

    string selector = SmartCardReader.GetDeviceSelector();

    DeviceInformationCollection smartCardReaders =
        await DeviceInformation.FindAllAsync(selector);

    foreach (var item in smartCardReaders)
        Console.WriteLine($"Connected device: {item.Name}");

When I plug in a SmartCardReader into my PC and run the console app, I see everything running as expected, the console app is succesfully accessing the Windows Runtime APIs: