Microsoft.Windows.CppWinRT 3.0.260715.1

Prefix Reserved

Requires NuGet 2.5 or higher.

dotnet add package Microsoft.Windows.CppWinRT --version 3.0.260715.1
                    
NuGet\Install-Package Microsoft.Windows.CppWinRT -Version 3.0.260715.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Microsoft.Windows.CppWinRT" Version="3.0.260715.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Microsoft.Windows.CppWinRT" Version="3.0.260715.1" />
                    
Directory.Packages.props
<PackageReference Include="Microsoft.Windows.CppWinRT" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Microsoft.Windows.CppWinRT --version 3.0.260715.1
                    
#r "nuget: Microsoft.Windows.CppWinRT, 3.0.260715.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Microsoft.Windows.CppWinRT@3.0.260715.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Microsoft.Windows.CppWinRT&version=3.0.260715.1
                    
Install as a Cake Addin
#tool nuget:?package=Microsoft.Windows.CppWinRT&version=3.0.260715.1
                    
Install as a Cake Tool

Microsoft.Windows.CppWinRT NuGet Package

Overview

Please visit Microsoft.Windows.CppWinRT for official Microsoft-signed builds of the NuGet package. See also the C++/WinRT VSIX, which provides C++/WinRT project templates and debug visualization.

To add build support for C++/WinRT vcxproj projects, add a reference to the Microsoft.Windows.CppWinRT NuGet package. This customizes your project's build rules to automatically generate C++/WinRT projection headers, enabling you to both consume and produce Windows Runtime classes.

C++/WinRT detects Windows metadata required by the project, from:

  • Platform winmd files in the SDK (both MSI and NuGet)
  • NuGet package references containing winmd files
  • Other project references producing winmd files
  • Raw winmd file references
  • Interface definition language (IDL) files in the project

For any winmd file discovered above, C++/WinRT creates reference (consuming) projection headers. Client code can simply #include these headers, which are created in the generated files directory (see below).

For any IDL file contained in the project, C++/WinRT creates component (producing) projection headers. In addition, C++/WinRT generates templates and skeleton implementations for each runtime class, under the generated files directory.

Details

C++/WinRT configures build rules for the following tools:

  • C++ compiler
  • C++/WinRT compiler
  • MdMerge utility
  • Midlrt utility
  • Xaml compiler

It sets the following project properties and item metadata:

| Property | Value | Description | |-|-|-| | PreferredToolArchitecture | x64 | Enables the compiler to use more memory | | CanReferenceWinRT | true | Enables native project references (e.g., to WinMD files) | | GeneratedFilesDir | *$(IntDir)Generated Files\ | Sets the folder for C++/WinRT generated source files | | XamlLanguage | CppWinRT | Directs the Xaml compiler to generate C++/WinRT code | | ClCompile.CompileAsWinRT | *false | Enables ISO C++ compilation (disables C++/CX) | | ClCompile.LanguageStandard | *stdcpp17 | Enables C++17 language features | | ClCompile.AdditionalOptions | /bigobj | Enables support for large object files | | ClCompile.AdditionalIncludeDirectories | GeneratedFilesDir | Adds $(GeneratedFilesDir) to the C++ include dirs | | Link.AdditionalDependencies | WindowsApp.lib | Umbrella library for Windows Runtime imports | | Midl.AdditionalOptions | /reference ... | Enables faster compilation with winmd references (versus idl imports) | | Midl.EnableWindowsRuntime | true | Enables Windows Runtime semantics | | Midl.MetadataFileName | Unmerged%(Filename).winmd | Generates unmerged metadata in a temporary location | | Midl.GenerateClientFiles, GenerateServerFiles, GenerateStublessProxies, GenerateTypeLibrary, HeaderFileName, DllDataFileName, InterfaceIdentifierFileName, ProxyFileName, TypeLibraryName | *nul, *None, *false | Disable unnecessary output | *If not already set

Generated Files

The generated files directory created by C++/WinRT contains two subfolders:

  • sources: runtime class skeleton implementations
  • winrt: reference projection headers

Customizing

C++/WinRT behavior can be customized with these project properties:

| Property | Value | Description | |-|-|-| | CppWinRTLibs | *true | false | Enables the Link item metadata settings above | | CppWinRTModernIDL | *true | false | Enables the Midl item metadata settings above | | CppWinRTVerbosity | low | *normal | high | Sets the importance of C++/WinRT build messages (see below) | | CppWinRTNamespaceMergeDepth | *1 | Sets the depth of namespace merging (Xaml apps require 1) | | CppWinRTRootNamespaceAutoMerge | true | *false | Sets the namespace merge depth to be the length of the root namespace | | CppWinRTMergeNoValidate | true | *false | Disables mdmerge validation | | CppWinRTUsePrefixes | *true | false | Uses a dotted prefix namespace convention (versus a nested folder convention) | | CppWinRTPath | ...\cppwinrt.exe | NuGet package-relative path to cppwinrt.exe, for custom build rule invocation | | CppWinRTParameters | "" | Custom cppwinrt.exe command-line parameters (be sure to append to existing) | | CppWinRTFastAbi | true | *false | Enables Fast ABI feature for both consuming and producing projections | | CppWinRTProjectLanguage | C++/CX | *C++/WinRT | Selects the C++ dialect for the project. C++/WinRT provides full projection support, C++/CX permits consuming projection headers. | | CppWinRTOptimized | true | *false | Enables component projection optimization features | | CppWinRTGenerateWindowsMetadata | true | *false | Indicates whether this project produces Windows Metadata | | CppWinRTEnableDefaultPrivateFalse | true | *false | Indicates whether this project uses C++/WinRT optimized default for copying binaries to the output directory | | CppWinRTBuildModule | true | *false | Generates per-namespace C++20 module interface units (.ixx) alongside projection headers | | CppWinRTModuleInclude | namespace list | Semicolon-delimited namespaces to include in module generation (default: all) | | CppWinRTModuleExclude | namespace list | Semicolon-delimited namespaces to exclude from module generation | *Default value

To customize common C++/WinRT project properties:

  • right-click the project node
  • expand the Common Properties item
  • select the C++/WinRT property page

InitializeComponent

In older versions of C++/WinRT, Xaml objects called InitializeComponent from constructors. This can lead to memory corruption if InitializeComponent throws an exception.

void MainPage::MainPage()
{
    // This pattern should no longer be used
    InitializeComponent();
}

C++/WinRT now calls InitializeComponent automatically and safely, after object construction. Explicit calls to InitializeComponent from constructors in existing code should now be removed. Multiple calls to InitializeComponent are idempotent.

If a Xaml object needs to access a Xaml property during initialization, it should override InitializeComponent:

void MainPage::InitializeComponent()
{
    // Call base InitializeComponent() to register with the Xaml runtime
    MainPageT::InitializeComponent();
    // Can now access Xaml properties
    MyButton().Content(box_value(L"Click"));
}

A non-Xaml object can also participate in two-phase construction by defining an InitializeComponent method.

void MyComponent::InitializeComponent()
{
    // Execute initialization logic that may throw 
}

[Windows|Microsoft]::UI::Xaml::Markup::ComponentConnectorT

A consequence of calling InitializeComponent outside construction is that Xaml runtime callbacks to IComponentConnector::Connect and IComponentConnector2::GetBindingConnector are now dispatched to the most derived implementations. Previously, these calls were dispatched directly to the class under construction, as the vtable had yet to be initialized. For objects with markup that derive from composable base classes with markup, this is a breaking change. Derived classes must now implement IComponentConnector::Connect and IComponentConnector2::GetBindingConnector by explicitly calling into the base class. The ComponentConnectorT template provides a correct implementation for these interfaces:

struct DerivedPage : winrt::Windows::UI::Xaml::Markup::ComponentConnectorT<DerivedPageT<DerivedPage>>

If overriding DerivedPage::InitializeComponent, ComponentConnectorT::InitializeComponent should be called instead of DerivedPageT::InitializeComponent:

void DerivedPage::InitializeComponent()
{
    // Call base InitializeComponent() to register with the Xaml runtime
    ComponentConnectorT::InitializeComponent();
    // Can now access Xaml properties from base or derived class
    MyBaseButton().Content(box_value(L"Click"));
}

C++20 Modules

C++/WinRT supports C++20 named modules as an alternative to #include-based consumption. Instead of #include <winrt/Windows.Foundation.h>, you can write import winrt.Windows.Foundation;.

See the C++/WinRT C++20 Modules Guide for the full guide (also shipped alongside this file as modules.md).

| ProjectReference metadata | Description | |-|-| | CppWinRTConsumeModule | true | *false | When set on a ProjectReference, consumes pre-built platform module IFCs from the referenced project | *Default value

Troubleshooting

The msbuild verbosity level maps to msbuild message importance as follows:

| Verbosity | Importance | |-|-| | q[uiet] | n/a | | m[inimal] | high | | n[ormal] | normal+ | | d[etailed], diag[nostic] | low+ | For example, if the verbosity is set to minimal, then only messages with high importance are generated. However, if the verbosity is set to diagnostic, then all messages are generated.

The default importance of C++/WinRT build messages is 'normal', but this can be overridden with the CppWinRTVerbosity property to enable throttling of C++/WinRT messages independent of the overall verbosity level.

Example:

msbuild project.vcxproj /verbosity:minimal /property:CppWinRTVerbosity=high ...

For more complex analysis of build errors, the MSBuild Binary and Structured Log Viewer is highly recommended.

Building, Testing

Be sure to get the latest nuget.exe from nuget.org and place it in your path.

Build the package by running build_nuget.cmd from a developer environment command line. For testing pass a version number that is much higher than your currently installed, like:

c:\repos\cppwinrt> .\build_nuget.cmd 5.0.0.0

Add the cppwinrt repo directory as a nuget source location and update your projects' references to point at it, update project references, then rebuild a test/sample project.

Product Compatible and additional computed target framework versions.
native native is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

NuGet packages (4)

Showing the top 4 NuGet packages that depend on Microsoft.Windows.CppWinRT:

Package Downloads
Unpackaged

Helpers for unpackaged and XAML Islands apps

WinUIEssential.WinUI3

Essential helpers for developing WinUI(UWP)

YexuanXiao.CppWinRTPlus.Ext

C++20 module interface extensions for C++/WinRT and Windows App SDK interop helpers.

WinUIEssential.WinUI3.Svg

SVG image source for WinUI3, backed by resvg. Provides WinUI3Package.Svg.SvgImageSource as a drop-in replacement for the built-in SvgImageSource with support for raw SVG strings, fragment-aware URI loading, and uniform rasterization to a target pixel size.

GitHub repositories (24)

Showing the top 20 popular GitHub repositories that depend on Microsoft.Windows.CppWinRT:

Repository Stars
files-community/Files
A modern file manager that helps users organize their files and folders.
mono/SkiaSharp
SkiaSharp is a cross-platform 2D graphics API for .NET platforms based on Google's Skia Graphics Library. It provides a comprehensive 2D API that can be used across mobile, server and desktop models to render images.
UnigramDev/Unigram
Telegram for Windows
dotnet/sdk
Core functionality needed to create .NET Core projects, that is shared between Visual Studio and CLI
ikas-mc/ContextMenuForWindows11
Add Custom Context Menu For Windows11
microsoft/AdaptiveCards
A new way for developers to exchange card content in a common and consistent way.
BedrockLauncher/BedrockLauncher
dotnet/dotnet
Home of .NET's Virtual Monolithic Repository which includes all the code needed to build the .NET SDK.
zhuxb711/RX-Explorer
一款优雅的UWP文件管理器 | An elegant UWP Explorer
melanchall/drywetmidi
Swiss knife for everything MIDI related
microsoft/CsWinRT
C# language projection for the Windows Runtime
microsoft/MixedRealityCompanionKit
This is a MixedRealityToolkit style repository for code bits and components that may not run directly on Microsoft HoloLens or immersive headsets but instead pair with them to build experiences.
microsoft/psi
Platform for Situated Intelligence
microsoft/react-native-windows-samples
A repository showcasing React Native samples and templates for Windows, macOS, and Surface Duo.
DrawnUi/DrawnUi.Net
Rendering engine for .NET MAUI, Blazor, OpenTK and pure .NET powered by SkiaSharp 🎨
CommunityToolkit/Microsoft.Toolkit.Win32
ARCHIVE - This repository contained XAML Islands wrapper controls and tooling for XAML Islands with WinUI 2, see readme for more info about XAML Islands with WinUI 3 and the WindowsAppSDK.
WindowsAppCommunity/Quarrel
Quarrel is a Discord client for Windows and Xbox that aims to bring voice chat to Xbox and improved support for varying screen sizes on devices running windows.
hpavlo/Rememory
Rememory | Clipboard Manager
microsoft/Win2D-Samples
Sample code showing how to use Win2D
microsoft/Windows-Camera
Tools and samples for camera related APIs on Windows
Version Downloads Last Updated
3.0.260715.1 1,860 7/16/2026
3.0.260520.1 27,753 5/22/2026
2.0.250303.1 303,379 5/29/2025
2.0.240405.15 596,213 4/5/2024
2.0.240111.5 125,166 1/12/2024
2.0.230706.1 568,255 7/6/2023
2.0.230524.4 16,127 5/25/2023
2.0.230524.3 3,685 5/24/2023
2.0.230225.1 168,867 2/25/2023
2.0.230207.1 510,164 2/7/2023
2.0.221121.5 339,293 11/21/2022
2.0.221117.1 20,852 11/17/2022
2.0.221104.6 123,034 11/4/2022
2.0.221101.3 4,035 11/1/2022
2.0.220929.3 60,509 9/29/2022
2.0.220912.1 29,254 9/12/2022
2.0.220909.4 3,228 9/12/2022
2.0.220608.4 144,085 6/8/2022
2.0.220607.4 5,538 6/8/2022
2.0.220531.1 357,605 6/1/2022
Loading failed