-
Notifications
You must be signed in to change notification settings - Fork 315
Add CMake sample apps for WinAppSDK deployment matrix #607
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ssparach
wants to merge
1
commit into
release/experimental
Choose a base branch
from
user/ssparach/CMakeSamples
base: release/experimental
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| #---------------------------------------------------------------------------------------------------------------------- | ||
| # CMakeBaselineTests - WinAppSDK Deployment Matrix Baseline Tests (CMake + NuGetCMakePackage) | ||
| #---------------------------------------------------------------------------------------------------------------------- | ||
| cmake_minimum_required(VERSION 3.31) | ||
|
|
||
| cmake_policy(SET CMP0141 NEW) | ||
| cmake_policy(SET CMP0117 NEW) | ||
|
|
||
| if(CMAKE_GENERATOR MATCHES "^Visual Studio") | ||
| file(WRITE "${CMAKE_BINARY_DIR}/Directory.Build.rsp" "-m -graphBuild:true -p:UseMultiToolTask=true -nodeReuse:false -terminalLogger:auto") | ||
| file(WRITE "${CMAKE_BINARY_DIR}/Directory.Build.props" "<Project></Project>") | ||
| file(WRITE "${CMAKE_BINARY_DIR}/Directory.Build.targets" "<Project></Project>") | ||
| elseif(CMAKE_GENERATOR MATCHES "^Ninja") | ||
| if(NOT (DEFINED ENV{Platform})) | ||
| message(FATAL_ERROR "When using the Ninja generator, you must build from a platform-specific Developer Command Prompt.") | ||
| endif() | ||
| endif() | ||
|
|
||
| project(CMakeBaselineTests LANGUAGES CXX) | ||
|
|
||
| include(FetchContent) | ||
|
|
||
| FetchContent_Declare( | ||
| NuGetCMakePackage | ||
| GIT_REPOSITORY https://github.com/mschofie/NuGetCMakePackage | ||
| GIT_TAG user/ssparach/prototype | ||
| ) | ||
|
|
||
| FetchContent_MakeAvailable(NuGetCMakePackage) | ||
|
|
||
| add_nuget_packages( | ||
| PACKAGES | ||
| Microsoft.Windows.CppWinRT 2.0.251203.1 | ||
| Microsoft.WindowsAppSDK.Foundation 2.0.15-preview | ||
| Microsoft.WindowsAppSDK.InteractiveExperiences 2.0.6-preview | ||
| Microsoft.WindowsAppSDK.Runtime 2.0.0-preview1 | ||
| ) | ||
|
|
||
| find_package(Microsoft.WindowsAppSDK.Foundation CONFIG REQUIRED) | ||
|
|
||
| # Common configuration | ||
| include(${CMAKE_SOURCE_DIR}/Configuration.cmake) | ||
| link_libraries(Configuration) | ||
|
|
||
| # Macro to copy runtime DLLs to the output directory | ||
| macro(post_build_runtime_dll_copy target_name) | ||
| if(WIN32) | ||
| add_custom_command(TARGET ${target_name} POST_BUILD | ||
| COMMAND "${CMAKE_COMMAND};-E;$<IF:$<BOOL:$<TARGET_RUNTIME_DLLS:${target_name}>>,copy;$<TARGET_RUNTIME_DLLS:${target_name}>;$<TARGET_FILE_DIR:${target_name}>,true>" | ||
| COMMAND_EXPAND_LISTS | ||
| ) | ||
| endif() | ||
| endmacro() | ||
|
|
||
| # Subdirectories | ||
| add_subdirectory(UnpackagedSelfContained) | ||
| add_subdirectory(UnpackagedFrameworkDependent) | ||
| add_subdirectory(PackagedSelfContained) | ||
| add_subdirectory(PackagedFrameworkDependent) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| { | ||
| "version": 6, | ||
| "cmakeMinimumRequired": { | ||
| "major": 3, | ||
| "minor": 31, | ||
| "patch": 0 | ||
| }, | ||
| "configurePresets": [ | ||
| { | ||
| "name": "vs2022-x64", | ||
| "displayName": "Visual Studio 2022 x64", | ||
| "generator": "Visual Studio 17 2022", | ||
| "architecture": "x64", | ||
| "binaryDir": "${sourceDir}/build/vs2022-x64" | ||
| }, | ||
| { | ||
| "name": "vs2022-arm64", | ||
| "displayName": "Visual Studio 2022 ARM64", | ||
| "generator": "Visual Studio 17 2022", | ||
| "architecture": "ARM64", | ||
| "binaryDir": "${sourceDir}/build/vs2022-arm64" | ||
| }, | ||
| { | ||
| "name": "ninja-x64", | ||
| "displayName": "Ninja Multi-Config x64", | ||
| "generator": "Ninja Multi-Config", | ||
| "binaryDir": "D:/b/nx64", | ||
| "cacheVariables": { | ||
| "CMAKE_OBJECT_PATH_MAX": "1000" | ||
| } | ||
| }, | ||
| { | ||
| "name": "ninja-arm64", | ||
| "displayName": "Ninja Multi-Config ARM64", | ||
| "generator": "Ninja Multi-Config", | ||
| "binaryDir": "D:/b/na64", | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TO DO: Update directory path here and allow long path support |
||
| "cacheVariables": { | ||
| "CMAKE_OBJECT_PATH_MAX": "1000" | ||
| } | ||
| } | ||
| ], | ||
| "buildPresets": [ | ||
| { | ||
| "name": "vs2022-x64-debug", | ||
| "configurePreset": "vs2022-x64", | ||
| "configuration": "Debug" | ||
| }, | ||
| { | ||
| "name": "vs2022-x64-release", | ||
| "configurePreset": "vs2022-x64", | ||
| "configuration": "Release" | ||
| }, | ||
| { | ||
| "name": "ninja-x64-debug", | ||
| "configurePreset": "ninja-x64", | ||
| "configuration": "Debug" | ||
| }, | ||
| { | ||
| "name": "ninja-x64-release", | ||
| "configurePreset": "ninja-x64", | ||
| "configuration": "Release" | ||
| } | ||
| ] | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| #---------------------------------------------------------------------------------------------------------------------- | ||
| # Common configuration for all baseline test apps | ||
| #---------------------------------------------------------------------------------------------------------------------- | ||
| add_library(Configuration INTERFACE) | ||
|
|
||
| target_compile_definitions(Configuration | ||
| INTERFACE | ||
| UNICODE | ||
| _UNICODE | ||
| NOMINMAX | ||
| WIN32_LEAN_AND_MEAN | ||
| ) | ||
|
|
||
| target_compile_features(Configuration | ||
| INTERFACE | ||
| cxx_std_20 | ||
| ) | ||
|
|
||
| target_compile_options(Configuration | ||
| INTERFACE | ||
| $<$<CXX_COMPILER_ID:MSVC>:/EHsc> | ||
| $<$<CXX_COMPILER_ID:MSVC>:/W3> | ||
| $<$<CXX_COMPILER_ID:MSVC>:/Zc:__cplusplus> | ||
| $<$<CXX_COMPILER_ID:MSVC>:/Zc:preprocessor> | ||
| ) | ||
|
|
||
| target_link_options(Configuration | ||
| INTERFACE | ||
| $<$<CXX_COMPILER_ID:MSVC>:$<$<NOT:$<CONFIG:Debug>>:/LTCG>> | ||
| $<$<CXX_COMPILER_ID:MSVC>:$<$<NOT:$<CONFIG:Debug>>:/INCREMENTAL:NO>> | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| # Copyright (c) Microsoft Corporation. | ||
| # Licensed under the MIT License. | ||
|
|
||
| <# | ||
| .SYNOPSIS | ||
| Registers and launches a packaged MSIX app with package identity. | ||
| .PARAMETER AppxManifestPath | ||
| Path to the AppxManifest.xml in the build output directory. | ||
| .PARAMETER PackageNameFilter | ||
| Wildcard filter to find the registered package (e.g., *CMake-PackagedSelfContained*). | ||
| .EXAMPLE | ||
| .\Launch-PackagedApp.ps1 -AppxManifestPath .\build\vs2022-x64\PackagedSelfContained\Debug\AppxManifest.xml -PackageNameFilter *CMake-PackagedSelfContained* | ||
| #> | ||
|
|
||
| param( | ||
| [Parameter(Mandatory)] | ||
| [string]$AppxManifestPath, | ||
|
|
||
| [Parameter(Mandatory)] | ||
| [string]$PackageNameFilter | ||
| ) | ||
|
|
||
| Set-StrictMode -Version 2.0 | ||
| $ErrorActionPreference = 'Stop' | ||
|
|
||
| # Step 1: Register | ||
| Write-Host "Registering MSIX layout: $AppxManifestPath" | ||
| Add-AppxPackage -Register $AppxManifestPath | ||
|
|
||
| # Step 2: Activate via COM IApplicationActivationManager (provides package identity) | ||
| Add-Type -TypeDefinition @" | ||
| using System; | ||
| using System.Runtime.InteropServices; | ||
| using System.Runtime.CompilerServices; | ||
|
|
||
| [ComImport, Guid("2e941141-7f97-4756-ba1d-9decde894a3d"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] | ||
| public interface IAppActivation { | ||
| IntPtr ActivateApplication([In] String appUserModelId, [In] String arguments, [In] UInt32 options, [Out] out UInt32 processId); | ||
| } | ||
|
|
||
| [ComImport, Guid("45BA127D-10A8-46EA-8AB7-56EA9078943C")] | ||
| public class AppActivation : IAppActivation { | ||
| [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)] | ||
| public extern IntPtr ActivateApplication([In] String appUserModelId, [In] String arguments, [In] UInt32 options, [Out] out UInt32 processId); | ||
| } | ||
| "@ -ErrorAction SilentlyContinue | ||
|
|
||
| $pkg = Get-AppxPackage | Where-Object { $_.Name -like $PackageNameFilter } | ||
| if (-not $pkg) { | ||
| Write-Error "Package not found matching '$PackageNameFilter'" | ||
| exit 1 | ||
| } | ||
|
|
||
| $aumid = "$($pkg.PackageFamilyName)!App" | ||
| Write-Host "Launching: $aumid" | ||
|
|
||
| $aam = New-Object AppActivation | ||
| $processId = [uint32]0 | ||
| $aam.ActivateApplication($aumid, $null, 0, [ref]$processId) | Out-Null | ||
|
|
||
| Write-Host "App launched with PID: $processId" | ||
| Write-Host "" | ||
| Write-Host "To unregister when done:" | ||
| Write-Host " Get-AppxPackage $PackageNameFilter | Remove-AppxPackage" | ||
|
|
||
| exit 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <!-- Copyright (c) Microsoft Corporation. Licensed under the MIT License --> | ||
| <Package | ||
| xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10" | ||
| xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10" | ||
| xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities" | ||
| IgnorableNamespaces="uap rescap"> | ||
| <Identity Name="CMake-PackagedFrameworkDependent" Publisher="CN=TestPublisher" Version="1.0.0.0" ProcessorArchitecture="x64" /> | ||
| <Properties> | ||
| <DisplayName>PackagedFrameworkDependent (CMake)</DisplayName> | ||
| <PublisherDisplayName>Microsoft</PublisherDisplayName> | ||
| <Logo>Logo.png</Logo> | ||
| </Properties> | ||
| <Dependencies> | ||
| <TargetDeviceFamily Name="Windows.Desktop" MinVersion="10.0.17763.0" MaxVersionTested="10.0.26100.0" /> | ||
| <PackageDependency Name="Microsoft.WindowsAppRuntime.2.0-preview1" MinVersion="0.772.1552.0" | ||
| Publisher="CN=Microsoft Corporation, O=Microsoft Corporation, L=Redmond, S=Washington, C=US" /> | ||
| </Dependencies> | ||
| <Resources> | ||
| <Resource Language="en-US" /> | ||
| </Resources> | ||
| <Applications> | ||
| <Application Id="App" Executable="PackagedFrameworkDependent.exe" EntryPoint="Windows.FullTrustApplication"> | ||
| <uap:VisualElements DisplayName="PackagedFrameworkDependent (CMake)" Description="Packaged framework-dependent CMake test" | ||
| BackgroundColor="transparent" Square150x150Logo="Logo.png" Square44x44Logo="Logo.png" /> | ||
| </Application> | ||
| </Applications> | ||
| <Capabilities> | ||
| <rescap:Capability Name="runFullTrust" /> | ||
| </Capabilities> | ||
| </Package> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| #---------------------------------------------------------------------------------------------------------------------- | ||
| # PackagedFrameworkDependent - Framework-dependent deployment with MSIX packaging | ||
| # | ||
| # After building, register the MSIX layout and launch via AUMID: | ||
| # Add-AppxPackage -Register <build-dir>\PackagedFrameworkDependent\AppxManifest.xml | ||
| # Start-Process "shell:AppsFolder\<PFN>!App" | ||
| #---------------------------------------------------------------------------------------------------------------------- | ||
| project(PackagedFrameworkDependent LANGUAGES CXX) | ||
|
|
||
| add_executable(PackagedFrameworkDependent WIN32 | ||
| main.cpp | ||
| ) | ||
|
|
||
| # Framework-dependent: use dynamic CRT | ||
| set_target_properties(PackagedFrameworkDependent PROPERTIES | ||
| MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL" | ||
| ) | ||
|
|
||
| # Use Foundation_Framework but without bootstrapper (MSIX provides framework package via package graph) | ||
| target_link_libraries(PackagedFrameworkDependent | ||
| PRIVATE | ||
| Microsoft.WindowsAppSDK.Foundation_Framework | ||
| ) | ||
|
|
||
| post_build_runtime_dll_copy(PackagedFrameworkDependent) | ||
|
|
||
| # Copy AppxManifest.xml and Logo to the output directory for MSIX registration | ||
| add_custom_command(TARGET PackagedFrameworkDependent POST_BUILD | ||
| COMMAND ${CMAKE_COMMAND} -E copy_if_different | ||
| ${CMAKE_CURRENT_SOURCE_DIR}/AppxManifest.xml | ||
| ${CMAKE_CURRENT_SOURCE_DIR}/Logo.png | ||
| $<TARGET_FILE_DIR:PackagedFrameworkDependent> | ||
| ) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| # PackagedFrameworkDependent | ||
|
|
||
| A native C++ WinAppSDK app that is **packaged** (MSIX) and **framework-dependent**, built with CMake and NuGetCMakePackage. | ||
|
|
||
| ## What this app demonstrates | ||
|
|
||
| - MSIX-packaged deployment with package identity | ||
| - Framework-dependent WinAppSDK deployment — the WinAppSDK Framework package is resolved via the MSIX package graph | ||
| - Standard dynamic CRT linking | ||
| - WinAppSDK EnvironmentManager API via C++/WinRT projections | ||
| - Manual AppxManifest with explicit `PackageDependency` on the WinAppSDK framework | ||
|
|
||
| ## Configuration | ||
|
|
||
| - CMake target: `Microsoft.WindowsAppSDK.Foundation_Framework` | ||
| - CRT: `MultiThreadedDLL` / `MultiThreadedDebugDLL` (standard dynamic CRT) | ||
| - MSIX packaging via manual `AppxManifest.xml` with `PackageDependency` on `Microsoft.WindowsAppRuntime.2.0-preview1` | ||
|
|
||
| ## Build | ||
|
|
||
| From the `CMakeBaselineTests/` directory: | ||
|
|
||
| ```powershell | ||
| # Configure (one-time) | ||
| cmake --preset vs2022-x64 | ||
|
|
||
| # Build | ||
| cmake --build --preset vs2022-x64-debug | ||
| ``` | ||
|
|
||
| Or for Release: | ||
|
|
||
| ```powershell | ||
| cmake --build --preset vs2022-x64-release | ||
| ``` | ||
|
|
||
| ## Launch | ||
|
|
||
| This app requires MSIX registration to get package identity and resolve the framework package: | ||
|
|
||
| ```powershell | ||
| # Step 1: Register the MSIX package layout | ||
| Add-AppxPackage -Register ".\build\vs2022-x64\PackagedFrameworkDependent\Debug\AppxManifest.xml" | ||
|
|
||
| # Step 2: Launch via shell activation (provides package identity + framework resolution) | ||
| $pfn = (Get-AppxPackage *CMake-PackagedFrameworkDependent*).PackageFamilyName | ||
| Start-Process "shell:AppsFolder\${pfn}!App" | ||
|
|
||
| # Step 3: Cleanup when done | ||
| Get-AppxPackage *CMake-PackagedFrameworkDependent* | Remove-AppxPackage | ||
| ``` | ||
|
|
||
| **Expected result:** A message box showing "Packaged Framework-Dependent App (CMake)" with the full package identity string, EnvironmentManager status, and the `PROCESSOR_ARCHITECTURE` value. | ||
|
|
||
| > **Note:** The app must be launched through the MSIX activation mechanism to have package identity. In Visual Studio, use F5 with the packaging project as startup. | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| - **WinAppSDK runtime** (`Microsoft.WindowsAppRuntime.2.0-preview1`) must be installed on the machine | ||
|
|
||
| ## Notes | ||
|
|
||
| - The `AppxManifest.xml` declares a `PackageDependency` on `Microsoft.WindowsAppRuntime.2.0-preview1` which causes Windows to resolve and load the framework package when the MSIX is activated. | ||
| - Unlike self-contained, the app has a smaller footprint since WinAppSDK binaries come from the shared framework package. | ||
| - No bootstrapper is used — the MSIX package graph handles framework resolution. |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TO DO: Update to point to latest hash on main once changes are committed