Skip to content

CsWinRT 3.0.0-preview.261104.1

Pre-release
Pre-release

Choose a tag to compare

@manodasanW manodasanW released this 09 Nov 19:59
· 2 commits to staging/3.0 since this release
eb2518b

This is an updated preview of CsWinRT 3.0, our rewrite of CsWinRT designed with AOT and trimming in mind from the start. This preview adds Windows Runtime component authoring support, improves build and runtime performance, and addresses issues found through testing and feedback since the first preview.

You can find more details on the design and breaking changes here.

Recommended: .NET SDK 10.0.400 or later

How to try it out

If targeting the 26100 OS version:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net10.0-windows10.0.26100.1</TargetFramework>
    <WindowsSdkPackageVersion>10.0.26100.88-preview</WindowsSdkPackageVersion>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.Windows.CsWinRT"
                      Version="3.0.0-preview.261104.1" />
  </ItemGroup>

</Project>

Reference projections

Projections generated by CsWinRT for distribution are reference assemblies, allowing applications to adopt newer CsWinRT versions independently of their dependencies. This preview improves automatic packaging of reference projections and now also ships a dedicated reference assembly for WinRT.Runtime, keeping implementation details out of the supported compile-time API surface.

You can find more details on creating and distributing projections here.

Multi-targeting

Libraries and applications can adopt CsWinRT 3.0 at their own pace by using the Windows OS version TFM with a .1 suffix, or multi-targeting both versions:

<!-- CsWinRT 2.x -->
<TargetFramework>net10.0-windows10.0.26100.0</TargetFramework>

<!-- CsWinRT 3.0 -->
<TargetFramework>net10.0-windows10.0.26100.1</TargetFramework>

The .NET SDK defines the CSWINRT3_0 preprocessor constant when CsWinRT 3.0 is active:

#if CSWINRT3_0
    // CsWinRT 3.0 specific code
#else
    // CsWinRT 2.x
#endif

You can find more details here.

Component authoring

Authoring Windows Runtime components in C# is now supported. Set CsWinRTComponent to true to generate component metadata and activation factories, with support for managed hosting and Native AOT deployment.

  • Post-build WinMD generation: Component metadata is generated from the public API surface of the compiled assembly.
  • Control the exported API: [ExcludeFromWindowsMetadata] lets public managed-only types and members remain available to C# callers without exporting them to Windows Runtime metadata.
  • Authoring diagnostics: New analyzers validate exported API shapes, versioning, overloads, activation factories, and array/span usage.

See the authoring guide for details.

Projection updates

  • Struct fields: Windows Runtime struct fields now project as public C# fields rather than properties, including manually projected foundation and XAML structs.
  • Deprecation and experimental APIs: Windows Runtime [Deprecated] metadata is supported, and [Experimental] APIs produce the .NET experimental diagnostic.
  • COM interop APIs: Added precomputed WindowsRuntimeMarshal.GetIid<T>() lookups and a ConvertToUnmanaged overload accepting an IID to obtain a specific native interface pointer.

AOT & trimming

This preview improves both the application-wide marshalling build pipeline and runtime behavior:

  • Incremental generation reuses the generated interop assembly when its marshalling inputs are unchanged.
  • Parallel discovery and emission improve build-tool throughput, with fixes for recursive generic discovery, forwarded types, and deterministic output.
  • Configurable discovery lets applications control marshalling support for platform-neutral libraries and explicitly include or exclude assemblies.
  • Runtime optimizations improve events, completed async operations, collection copying, and exception handling.
  • Lifetime and cleanup fixes address event-cache leaks, async-operation lifetime, pooled array marshalling, and native resource cleanup.

See the AOT and trimming documentation for more details.

Known limitations and breaking changes

See the breaking changes documented in the first preview.

Packages

Both the CsWinRT package and the updated Windows SDK targeting package are required to be referenced to use this preview:

C#/WinRT package:

https://www.nuget.org/packages/Microsoft.Windows.CsWinRT/3.0.0-preview.261104.1

.NET Windows SDK targeting package:

<WindowsSdkPackageVersion>10.0.xxxxx.88-preview</WindowsSdkPackageVersion>

https://www.nuget.org/packages/Microsoft.Windows.SDK.NET.Ref/10.0.26100.88-preview
https://www.nuget.org/packages/Microsoft.Windows.SDK.NET.Ref/10.0.22621.88-preview
https://www.nuget.org/packages/Microsoft.Windows.SDK.NET.Ref/10.0.22000.88-preview
https://www.nuget.org/packages/Microsoft.Windows.SDK.NET.Ref/10.0.19041.88-preview
https://www.nuget.org/packages/Microsoft.Windows.SDK.NET.Ref/10.0.18362.88-preview
https://www.nuget.org/packages/Microsoft.Windows.SDK.NET.Ref/10.0.17763.88-preview

Feedback

This is a preview release and we'd love your feedback! Please file issues on GitHub and tag them with CsWinRT 3.0. For questions and discussions, use GitHub Discussions.

Full Changelog: 3.0.0-preview.260319.2...3.0.0-preview.261104.1