News

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 at Converge 360.

comments powered by Disqus

Featured

  • Mastering Blazor Authentication and Authorization

    At the Visual Studio Live! @ Microsoft HQ developer conference set for August, Rockford Lhotka will explain the ins and outs of authentication across Blazor Server, WebAssembly, and .NET MAUI Hybrid apps, and show how to use identity and claims to customize application behavior through fine-grained authorization.

  • Linear Support Vector Regression from Scratch Using C# with Evolutionary Training

    Dr. James McCaffrey from Microsoft Research presents a complete end-to-end demonstration of the linear support vector regression (linear SVR) technique, where the goal is to predict a single numeric value. A linear SVR model uses an unusual error/loss function and cannot be trained using standard simple techniques, and so evolutionary optimization training is used.

  • Low-Code Report Says AI Will Enhance, Not Replace DIY Dev Tools

    Along with replacing software developers and possibly killing humanity, advanced AI is seen by many as a death knell for the do-it-yourself, low-code/no-code tooling industry, but a new report belies that notion.

  • Vibe Coding with Latest Visual Studio Preview

    Microsoft's latest Visual Studio preview facilitates "vibe coding," where developers mainly use GitHub Copilot AI to do all the programming in accordance with spoken or typed instructions.

  • Steve Sanderson Previews AI App Dev: Small Models, Agents and a Blazor Voice Assistant

    Blazor creator Steve Sanderson presented a keynote at the recent NDC London 2025 conference where he previewed the future of .NET application development with smaller AI models and autonomous agents, along with showcasing a new Blazor voice assistant project demonstrating cutting-edge functionality.

Subscribe on YouTube