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 for Converge360.

comments powered by Disqus

Featured

  • AI for GitHub Collaboration? Maybe Not So Much

    No doubt GitHub Copilot has been a boon for developers, but AI might not be the best tool for collaboration, according to developers weighing in on a recent social media post from the GitHub team.

  • Visual Studio 2022 Getting VS Code 'Command Palette' Equivalent

    As any Visual Studio Code user knows, the editor's command palette is a powerful tool for getting things done quickly, without having to navigate through menus and dialogs. Now, we learn how an equivalent is coming for Microsoft's flagship Visual Studio IDE, invoked by the same familiar Ctrl+Shift+P keyboard shortcut.

  • .NET 9 Preview 3: 'I've Been Waiting 9 Years for This API!'

    Microsoft's third preview of .NET 9 sees a lot of minor tweaks and fixes with no earth-shaking new functionality, but little things can be important to individual developers.

  • Data Anomaly Detection Using a Neural Autoencoder with C#

    Dr. James McCaffrey of Microsoft Research tackles the process of examining a set of source data to find data items that are different in some way from the majority of the source items.

  • What's New for Python, Java in Visual Studio Code

    Microsoft announced March 2024 updates to its Python and Java extensions for Visual Studio Code, the open source-based, cross-platform code editor that has repeatedly been named the No. 1 tool in major development surveys.

Subscribe on YouTube