Authoring Windows Runtime components with C#/WinRT is supported on .NET 6 and later.
The C#/WinRT NuGet package provides support for authoring your own Windows Runtime types and components in C#, and consuming them from any Windows Runtime-compatible language such as C++/WinRT or Rust. C#/WinRT authoring and hosting support requires .NET 6 and Visual Studio 2022, and it is intended to support desktop application scenarios including the Windows App SDK, and WinUI3.
While authoring your Windows Runtime component, follow the guidelines and type restrictions outlined in the existing UWP documentation about Windows Runtime components (see Windows Runtime components with C# and Visual Basic). The component can for the most part be implemented like any other C# library. However, there are restrictions on the public types in the component that will be exposed to the Windows Runtime and declared in the generated .winmd for others to consume.
Externally, you can expose only Windows Runtime types for parameters and return values. You can use built-in C# types as part of the public surface of the component as long as there is a mapping from the .NET type to WinRT (see .NET mappings of WinRT types in C#/WinRT), and they will appear to users of the component as the corresponding Windows Runtime types. Windows Runtime types from other Windows Runtime components and the Windows SDK can also be used as part of the public implementation of the component, such as in parameters, return types, and class inheritance.
Notitie
There are some Windows Runtime types that are mapped to .NET types (see .NET mappings of WinRT types in C#/WinRT). These .NET types can be used in the public interface of your Windows Runtime component, and they will appear to users of the component as the corresponding Windows Runtime types.
De bron voor deze inhoud vindt u op GitHub, waar u ook problemen en pull-aanvragen kunt maken en controleren. Bekijk onze gids voor inzenders voor meer informatie.
Windows developer-feedback
Windows developer is een open source project. Selecteer een koppeling om feedback te geven:
In this topic, we walk through using [C#/WinRT](/windows/uwp/csharp-winrt/) to generate a C# .NET projection (or interop) assembly from a C++/WinRT Windows Runtime component, and distribute it as a NuGet package for .NET applications.
An agile object is one that can be accessed from any thread. C#/WinRT provides support for agile references if you need to marshal a non-agile object across apartments in a safe way.