Microsoft has nudged out an update to the C#/WinRT NuGet package and added a preview of C#/WinRT authoring to an otherwise relatively humdrum release.
Lurking among the tweaks and bugfixes, the arrival of authoring (in preview) means that C# .NET 5 component authors can create their own Windows Runtime types and package them as Windows Runtime components.
“You can implement runtime classes in a C# library project, generate its WinMD metadata file, and distribute the WinRT component as a NuGet package,” explained Microsoft. “C#/WinRT provides hosting support which loads the .NET runtime.”
It’s a neat bit of functionality, and the preview permits a C# authored component to be consumed by the likes of C++ and Rust. Sadly, WinUI3 is not, as Microsoft delicately put it, “fully supported”. It is instead due to receive some love in the coming months.
We took our copy of Visual Studio out for a spin and, having created a new C# project using the Class Library template and pointing it at .NET 5, creating the usual “Hello World” was relatively straightforward once a NuGet reference to the C#/WinRT package was made.
Persuading another language to consume it was a little more complicated. We went down the package reference route with a C++ console application and, after some tinkering with JSON and poking at the manifest, were rewarded with that “Hello World”.
The authoring functionality, when in a state that doesn’t require quite so much hand-holding, will allow C# .NET 5 fans to package their own Windows Runtime components that can be consumed in native applications. As it stands, however, that Preview label is well deserved – there is plenty of potential for coders that would benefit from this functionality but, as Microsoft would agree, more work remains before it can be allowed near production code.
The plan is to “continue to improve the project support for a more streamlined end-to-end authoring experience,” according to Microsoft, as well as “working on support for more authoring scenarios such as integration with WinUI 3 desktop applications and authoring out-of-process components.” ®