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

  • Compare New GitHub Copilot Free Plan for Visual Studio/VS Code to Paid Plans

    The free plan restricts the number of completions, chat requests and access to AI models, being suitable for occasional users and small projects.

  • Diving Deep into .NET MAUI

    Ever since someone figured out that fiddling bits results in source code, developers have sought one codebase for all types of apps on all platforms, with Microsoft's latest attempt to further that effort being .NET MAUI.

  • Copilot AI Boosts Abound in New VS Code v1.96

    Microsoft improved on its new "Copilot Edit" functionality in the latest release of Visual Studio Code, v1.96, its open-source based code editor that has become the most popular in the world according to many surveys.

  • AdaBoost Regression Using C#

    Dr. James McCaffrey from Microsoft Research presents a complete end-to-end demonstration of the AdaBoost.R2 algorithm for regression problems (where the goal is to predict a single numeric value). The implementation follows the original source research paper closely, so you can use it as a guide for customization for specific scenarios.

  • Versioning and Documenting ASP.NET Core Services

    Building an API with ASP.NET Core is only half the job. If your API is going to live more than one release cycle, you're going to need to version it. If you have other people building clients for it, you're going to need to document it.

Subscribe on YouTube