diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 000000000..becb351d7 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,58 @@ +name: Release NuGet + +on: + release: + types: [published] + +jobs: + publish: + permissions: + id-token: write + contents: write + runs-on: windows-2025-vs2026 + steps: + - uses: actions/checkout@v6 + + - name: Build and pack + shell: pwsh + run: | + $version = "${{ github.event.release.tag_name }}" -replace '^v', '' + $VSDevCmd = & "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere" -latest -find Common7\tools\VSDevCmd.bat + echo "Using VSDevCmd: ${VSDevCmd}" + cmd /c "${VSDevCmd}" "&" nuget.exe restore cppwinrt.sln + cmd /c "${VSDevCmd}" "&" build_vsix.cmd Release "${version}" + if (!(Test-Path "*.nupkg")) { + echo "::error::Output nuget package not found!" + exit 1 + } + if (!(Test-Path "vsix\Dev17\bin\Release\Standalone\Microsoft.Windows.CppWinRT.Dev17.vsix")) { + echo "::error::Output vsix package not found!" + exit 1 + } + + - name: NuGet login + uses: NuGet/login@v1 + id: login + with: + user: YexuanXiao + + - name: NuGet push + run: | + $version = "${{ github.event.release.tag_name }}" -replace '^v', '' + $packageName = "YexuanXiao.CppWinRTPlus.${version}.nupkg" + dotnet nuget push $packageName --api-key ${{steps.login.outputs.NUGET_API_KEY}} --source https://api.nuget.org/v3/index.json + + - name: Upload to Release + shell: pwsh + run: | + $headers = @{ + "Authorization" = "Bearer ${{ secrets.GITHUB_TOKEN }}" + "Content-Type" = "application/octet-stream" + } + $version = "${{ github.event.release.tag_name }}" -replace '^v', '' + $packageName = "YexuanXiao.CppWinRTPlus.${version}.nupkg" + $url = "https://uploads.github.com/repos/${{ github.repository }}/releases/${{ github.event.release.id }}/assets?name=${packageName}" + Invoke-RestMethod -Uri $url -Method POST -Headers $headers -InFile $packageName + $vsixName = "Microsoft.Windows.CppWinRT.Dev17.${version}.vsix" + $url = "https://uploads.github.com/repos/${{ github.repository }}/releases/${{ github.event.release.id }}/assets?name=${vsixName}" + Invoke-RestMethod -Uri $url -Method POST -Headers $headers -InFile "vsix\Dev17\bin\Release\Standalone\Microsoft.Windows.CppWinRT.Dev17.vsix" diff --git a/LICENSE b/LICENSE index 9e841e7a2..5925bdb12 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,7 @@ MIT License Copyright (c) Microsoft Corporation. + Copyright (c) 2026 YexuanXiao and The C++/WinRT Plus Project. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 19e1493dc..b3346e2e6 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,35 @@ +# C++/WinRT Plus + +[![CI Tests](https://github.com/YexuanXiao/cppwinrtplus/actions/workflows/ci.yml/badge.svg)](https://github.com/YexuanXiao/cppwinrtplus/actions/workflows/ci.yml) + +C++/WinRT Plus is a community-driven evolution of the original C++/WinRT project. This independent initiative is neither affiliated with nor sponsored by Microsoft. Our mission is to address long-standing issues in C++/WinRT and deliver meaningful improvements to the developer experience. While the project introduces some breaking changes, we provide a simple and smooth migration path. You can continue using it just as you would with C++/WinRT. + +We're deeply grateful to the original authors of C++/WinRT for their groundbreaking work, which gave the C++ community first-class access to the Windows Runtime. + +With development on the original project slowing, we believe it's time for the community to take the lead. C++/WinRT Plus builds on that strong foundation—preserving what works while addressing the issues that matter most to daily users. Join us in shaping the future of Windows Runtime development in C++. + +## How to use + +You can install the package directly via NuGet with the ID YexuanXiao.CppWinRTPlus. + +## Roadmap + +The current plans for C++/WinRT Plus can be viewed in the issue list. C++/WinRT Plus currently has many ambitious improvements, so your help is greatly needed! + +## Changelog + +Since the C++/WinRT mainline has accepted our module implementation, C++/WinRT Plus is now rebased onto the C++/WinRT 3.0 mainline to maintain compatibility. + +All the changes listed here only show the differences from the C++/WinRT mainline, and once the C++/WinRT Plus commits are merged upstream, they will be removed. + +2026/09/17: + +1. C++/WinRT Plus can now work with our VSIX extension to provide visualization for WinRT types in third-party NuGet packages (such as WindowsAppSDK). +2. Fixed the issue where XamlMetadataProvider.cpp still requires the pch.h even when it is disabled. +3. Optimized the performance of winrt::to_string using C++23's new resize_and_overwrite function. + +2026/03/24: Support using lambdas with explicit object parameter as delegates to resolve the issue where the captured lifetime may be shorter than the lifetime of the coroutine frame. + # The C++/WinRT language projection C++/WinRT is an entirely standard C++ language projection for Windows Runtime (WinRT) APIs, implemented as a header-file-based library, and designed to provide you with first-class access to the modern Windows API. With C++/WinRT, you can author and consume Windows Runtime APIs using any standards-compliant C++17 compiler. diff --git a/nuget/Microsoft.Windows.CppWinRT.nuspec b/nuget/Microsoft.Windows.CppWinRT.nuspec index 52151fc08..8c5b45e9c 100644 --- a/nuget/Microsoft.Windows.CppWinRT.nuspec +++ b/nuget/Microsoft.Windows.CppWinRT.nuspec @@ -1,19 +1,19 @@ - Microsoft.Windows.CppWinRT + YexuanXiao.CppWinRTPlus $target_version$ - C++/WinRT Build Support - Microsoft - Microsoft + C++/WinRT Plus Build Support + YexuanXiao + YexuanXiao + readme.md false - C++/WinRT is a standard C++ language projection for the Windows Runtime implemented solely in header files. It allows you to both author and consume Windows Runtime APIs using any standards-compliant C++ compiler. C++/WinRT is designed to provide C++ developers with first-class access to the modern Windows API. + C++/WinRT Plus is a standard C++ language projection for the Windows Runtime implemented solely in header files. It allows you to both author and consume Windows Runtime APIs using any standards-compliant C++ compiler. C++/WinRT Plus is designed to provide C++ developers with first-class access to the modern Windows API. native C++ WinRT nativepackage - © Microsoft Corporation. All rights reserved. + Copyright (c) Microsoft Corporation. All rights reserved. Copyright (c) 2026 C++/WinRT Plus Project. All rights reserved. LICENSE - readme.md - https://github.com/Microsoft/cppwinrt + https://github.com/YexuanXiao/cppwinrtplus https://aka.ms/cppwinrt.ico diff --git a/nuget/readme.md b/nuget/readme.md index 16eb5d2bb..f124a665f 100644 --- a/nuget/readme.md +++ b/nuget/readme.md @@ -1,4 +1,20 @@ -# Microsoft.Windows.CppWinRT NuGet Package +# YexuanXiao.CppWinRTPlus NuGet Package + +Please read the [repository](https://github.com/YexuanXiao/cppwinrtplus)'s README.md for usage instructions. + +## Changelog + +Since the C++/WinRT mainline has accepted our module implementation, C++/WinRT Plus is now rebased onto the C++/WinRT 3.0 mainline to maintain compatibility. + +All the changes listed here only show the differences from the C++/WinRT mainline, and once the C++/WinRT Plus commits are merged upstream, they will be removed. + +2026/09/17: + +1. C++/WinRT Plus can now work with our VSIX extension to provide visualization for WinRT types in third-party NuGet packages (such as WindowsAppSDK). +2. Fixed the issue where XamlMetadataProvider.cpp still requires the pch.h even when it is disabled. +3. Optimized the performance of winrt::to_string using C++23's new resize_and_overwrite function. + +2026/03/24: Support using lambdas with explicit object parameter as delegates to resolve the issue where the captured lifetime may be shorter than the lifetime of the coroutine frame. ## Overview @@ -7,11 +23,12 @@ Please visit [Microsoft.Windows.CppWinRT](https://www.nuget.org/packages/Microso 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 +* 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). @@ -20,6 +37,7 @@ For any IDL file contained in the project, C++/WinRT creates component (producin ## Details C++/WinRT configures build rules for the following tools: + * C++ compiler * C++/WinRT compiler * MdMerge utility @@ -30,25 +48,28 @@ It sets the following project properties and item metadata: | Property | Value | Description | |-|-|-| -| [PreferredToolArchitecture](https://docs.microsoft.com/en-us/cpp/build/msbuild-visual-cpp-overview?view=vs-2017) | x64 | Enables the compiler to use more memory | +| [PreferredToolArchitecture](https://learn.microsoft.com/en-us/cpp/build/reference/msbuild-visual-cpp-overview?view=msvc-180) | 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.LanguageStandard | *stdcpp20 | Enables C++20 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 +| 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 + +* sources: runtime class skeleton implementations +* winrt: reference projection headers ## Customizing @@ -58,28 +79,120 @@ C++/WinRT behavior can be customized with these project properties: |-|-|-| | 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](https://docs.microsoft.com/en-us/visualstudio/msbuild/message-task?view=vs-2017) of C++/WinRT build messages (see below) | +| CppWinRTVerbosity | low \| *normal \| high | Sets the [importance](https://learn.microsoft.com/en-us/visualstudio/msbuild/message-task?view=visualstudio) 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) | +| CppWinRTUseModules | true \| *false | Generate C++ modules (ixx) for each namespaces | | 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](https://kennykerr.ca/2019/06/07/cppwinrt-optimizing-components/) | | 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: +To customize common C++/WinRT project properties: + * right-click the project node * expand the Common Properties item * select the C++/WinRT property page +## Exclude what you don't want + +You can prevent unnecessary namespaces from being generated, such as, by adding a CppWinRT.config file to the solution directory. Since some modules are very large, this can effectively reduce compilation time. + +The format of the configuration file is: + +```xml + + + + Windows.Foundation + + + Windows.UI.Xaml + Windows.ApplicationModel.Store + + +``` + +It is equivalent to passing `-config `, you can write `import winrt.Windows.Foundation;`. - -See the [C++/WinRT C++20 Modules Guide](https://github.com/microsoft/cppwinrt/blob/master/nuget/modules.md) 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: @@ -156,7 +258,8 @@ The msbuild verbosity level maps to msbuild message importance as follows: | 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. + +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.