C#/WinRT Authoring Preview Unveiled

Microsoft unveiled a preview of authoring support in an update to the C#/WinRT tool used to help C# developers more easily work with interfaces to the Windows Runtime, the underlying infrastructure used by Windows to expose its APIs.

The C#/WinRT GitHub site says it "provides Windows Runtime (WinRT) projection support for the C# language. A 'projection' is an adapter that enables programming the WinRT APIs in a natural and familiar way for the target language. The C#/WinRT projection hides the details of interop between C# and WinRT interfaces, and provides mappings of many WinRT types to appropriate .NET equivalents, such as strings, URIs, common value types, and generic collections."

WinRT, first introduced in 2012 with Windows 8 and Windows Server 2012, succeeds the older, flat, C-based Win32 API.

Microsoft removed built-in support for C#/WinRT last summer in a .NET 5 preview, transferring it to NuGet where it has been downloaded more than 33,000 times. Documentation describing C#/WinRT says:

Previous versions of .NET Framework and .NET Core had built-in knowledge of WinRT, a Windows-specific technology. To support the portability and efficiency goals of .NET 5, we lifted the WinRT projection support out of the .NET compiler and runtime and moved it into the C#/WinRT toolkit. The goal of C#/WinRT is to provide parity with the built-in WinRT support provided by earlier versions of the C# compiler and .NET runtime.
A C++/WinRT tool has been around for several years now, downloaded more than 715,000 times from NuGet and more than 73,000 times as an extension in the Visual Studio Marketplace (there is no equivalent C#/WinRT extension).

Referencing an Interop Assembly
[Click on image for larger view.] Referencing an Interop Assembly (source: Microsoft).

The C#/WinRT tool -- currently in prerelease version 1.1.2 on NuGet -- is compatible with .NET 5 and does not require built-in knowledge of WinRT by the C# compiler, its description says.

In announcing an update to the tool, which hit v1.0 general availability in November along with .NET 5, Microsoft announced the preview support for authoring. "This allows component authors to create and package their own C# .NET 5 Windows Runtime components that can be consumed in native applications," Microsoft said.

The Feb. 9 post goes on to describe how to author a WinRT component, build and package it, consume it from a native application and more, including updates for the .NET 5.0 SDK February update with C#/WinRT version 1.1.1. The post also describes bug fixes and a new feature: support for SupportedOSPlatform attributes. "With the integration of these attribute checks in Visual Studio, you now get a CA1416 warning when calling platform-specific APIs that are not supported on the platform versions your project supports."

Going forward, the dev team is planning to add support for more authoring scenarios, including integration with WinUI 3 desktop applications, along with authoring out-of-process components for use in packaged applications.

About the Author

David Ramel is an editor and writer for Converge360.

comments powered by Disqus


  • VS Code Now Has Apple Silicon Builds for Native Mac Development

    Goodbye Rosetta, hello M1. Visual Studio Code has been updated with new builds that let it run natively on machines with Apple Silicon (M1), the company's own ARM64 chips.

  • Visual Studio 2019 for Mac v8.9 Ships with .NET 6 Preview 1 Support

    During its Ignite 2021 online event for IT pros and developers this week, Microsoft shipped Visual Studio 2019 for Mac v8.9, arriving with out-of-the-box support for .NET 6 Preview 1, which the company also released recently.

  • Analyst: TypeScript Now Firmly in Top 10 Echelon (Ruby, Not So Much)

    RedMonk analyst Stephen O'Grady believes TypeScript has achieved the rare feat of firmly ensconcing itself into the top 10 echelon of his ranking, now questioning how high it might go.

  • Black White Wave IMage

    Neural Regression Using PyTorch: Training

    The goal of a regression problem is to predict a single numeric value, for example, predicting the annual revenue of a new restaurant based on variables such as menu prices, number of tables, location and so on.

Upcoming Events