Skip to content

Commit 158d49f

Browse files
andrewleaderCopilotCopilot
authored
Updated WinML docs for WASDK 1.8.6 and 2.0-Exp6 release (#1132)
* Initial flat C edits * Some more updates * Update about try-catch * Small updates * Naming fix * CMAKE docs * Remove accidental sample * Add ORT versions * Update initialize-execution-providers.md * Update register-execution-providers.md * Update versioning.md * Fix tabs in run ONNX models * Fix review feedback: CMake casing, C++20 standard, ms.date, and null guards in callbacks (#1133) * Initial plan * Fix review comments: CMake casing, C++20 standard, ms.date updates, null checks Co-authored-by: andrewleader <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: andrewleader <[email protected]> * Update to C APIs * Update overview.md * Apply suggestions from code review Co-authored-by: Copilot <[email protected]> * Fix tab name * Bumping release to 3/11 * Update onnx-versions.md * Final 1.8.6 release --------- Co-authored-by: Copilot <[email protected]> Co-authored-by: andrewleader <[email protected]> Co-authored-by: Copilot <[email protected]>
1 parent 4c2fd94 commit 158d49f

12 files changed

Lines changed: 629 additions & 55 deletions

docs/new-windows-ml/distributing-your-app.md

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,21 @@
11
---
22
title: Deploy your app that uses Windows ML
33
description: Learn how to deploy your app that uses Windows Machine Learning (ML).
4-
ms.date: 07/07/2025
4+
ms.date: 03/10/2026
55
ms.topic: concept-article
66
---
77

88
# Deploy your app that uses Windows ML
99

10-
When you're ready to distribute your C# or C++ app that uses Windows ML, you need to ensure that the Windows App SDK framework is properly deployed to your users' devices. The Windows ML runtime is distributed as part of the Windows App SDK.
10+
Windows ML is deployed like any other Windows App SDK component, supporting both framework-dependent and self-contained deployment. See the [Windows App SDK deployment overview](/windows/apps/package-and-deploy/deploy-overview) for more details about the deployment options in Windows App SDK.
1111

12-
## Supported deployment options for Windows ML
13-
14-
Windows ML supports both the framework-dependent and the self-contained deployment options in Windows App SDK. See the [Windows App SDK deployment overview](/windows/apps/package-and-deploy/deploy-overview) for more details about the deployment options in Windows App SDK.
15-
16-
### Framework-dependent: ✅ Supported
12+
## Framework-dependent
1713

1814
Your app depends on the Windows App SDK runtime and/or framework package being present on the target machine. Framework-dependent deployment is the default deployment mode of the Windows App SDK for its efficient use of machine resources and serviceability. See [Deployment architecture and overview for framework-dependent apps](/windows/apps/windows-app-sdk/deployment-architecture) for more details.
1915

20-
### Self-contained: ✅ Supported
16+
## Self-contained
2117

22-
With the GA release of Windows ML, use of the self-contained deployment option in Windows App SDK is now supported when using Windows ML. See [Deployment guide for self-contained apps](/windows/apps/package-and-deploy/self-contained-deploy/deploy-self-contained-apps) for more details.
18+
Your app carries the Windows App SDK dependencies with it. See [Deployment guide for self-contained apps](/windows/apps/package-and-deploy/self-contained-deploy/deploy-self-contained-apps) for more details.
2319

2420
In self-contained mode, ONNX Runtime binaries are deployed alongside your application:
2521

docs/new-windows-ml/get-started.md

Lines changed: 119 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,28 +21,90 @@ If you're not already familiar with the ONNX Runtime, we suggest reading the [ON
2121
* .NET 6 or greater
2222
* Targeting a Windows 10-specific TFM like `net6.0-windows10.0.19041.0` or greater
2323

24-
### [C++](#tab/cppwinrt)
24+
### [C++/WinRT](#tab/cppwinrt)
2525

2626
C++20 or later.
2727

28+
### [C/C++](#tab/c)
29+
30+
* Visual Studio 2022 with C++ workload (includes the C compiler)
31+
* CMake 3.21 or later
32+
2833
### [Python](#tab/python)
2934

3035
Python versions 3.10 to 3.13, on x64 and ARM64 devices.
3136

3237
---
3338

34-
## Step 1: Install or update the Windows App SDK
35-
36-
Windows ML is included in [Windows App SDK 1.8.1 or greater](/windows/apps/windows-app-sdk/stable-channel).
39+
## Step 1: Install or update Windows ML
3740

3841
### [C#](#tab/csharp)
3942

43+
Windows ML is included in [Windows App SDK 1.8.1 or greater](/windows/apps/windows-app-sdk/stable-channel).
44+
4045
See [use the Windows App SDK in an existing project](/windows/apps/windows-app-sdk/use-windows-app-sdk-in-existing-project) for how to add the Windows App SDK to your project, or if you're already using Windows App SDK, update your packages.
4146

42-
### [C++](#tab/cppwinrt)
47+
### [C++/WinRT](#tab/cppwinrt)
48+
49+
Windows ML is included in [Windows App SDK 1.8.1 or greater](/windows/apps/windows-app-sdk/stable-channel).
4350

4451
See [use the Windows App SDK in an existing project](/windows/apps/windows-app-sdk/use-windows-app-sdk-in-existing-project) for how to add the Windows App SDK to your project, or if you're already using Windows App SDK, update your packages.
4552

53+
### [C/C++](#tab/c)
54+
55+
Windows ML C APIs are included in the [`Microsoft.WindowsAppSDK.ML` NuGet package](https://www.nuget.org/packages/Microsoft.WindowsAppSDK.ML) version 1.8.6 or greater. The NuGet package ships CMake config files under `build/cmake/` that are directly consumable. The `@WINML_VERSION@` token is resolved at NuGet build time, so no additional processing is required.
56+
57+
To use the NuGet package...
58+
59+
1. Download or restore the NuGet package (e.g., via `nuget restore` or manual download)
60+
2. Extract or reference the package root directory
61+
3. Set `CMAKE_PREFIX_PATH` to the `build/cmake` subdirectory of the package
62+
63+
**Example CMakeLists.txt**
64+
65+
```cmake
66+
cmake_minimum_required(VERSION 3.21)
67+
project(MyApp LANGUAGES CXX)
68+
69+
# C++20 standard for modern features (std::format, etc.)
70+
set(CMAKE_CXX_STANDARD 20)
71+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
72+
73+
find_package(microsoft.windows.ai.machinelearning CONFIG REQUIRED)
74+
75+
add_executable(MyApp main.cpp)
76+
target_link_libraries(MyApp PRIVATE WindowsML::Api WindowsML::OnnxRuntime)
77+
78+
add_custom_command(TARGET MyApp POST_BUILD
79+
COMMAND ${CMAKE_COMMAND} -E copy_if_different
80+
$<TARGET_RUNTIME_DLLS:MyApp> $<TARGET_FILE_DIR:MyApp>
81+
COMMAND_EXPAND_LISTS
82+
VERBATIM
83+
)
84+
```
85+
86+
**Example Build Commands**
87+
88+
```powershell
89+
# Point CMAKE_PREFIX_PATH to the NuGet package's cmake directory
90+
cmake -B build -S . -DCMAKE_PREFIX_PATH="C:/packages/Microsoft.WindowsAppSDK.ML/build/cmake"
91+
cmake --build build --config Release
92+
```
93+
94+
The NuGet package ships its own cmake config under `build/cmake/` that understands
95+
the NuGet directory structure (architecture-specific directories under `lib/native/`
96+
and `runtimes/`). Architecture is determined from `CMAKE_GENERATOR_PLATFORM`,
97+
`CMAKE_VS_PLATFORM_NAME`, or `CMAKE_SYSTEM_PROCESSOR`.
98+
99+
The vcpkg portfile generates a separate, thin config file that maps to the standard
100+
vcpkg layout (`lib/` and `bin/`). Both configs share the same targets file
101+
(`microsoft.windows.ai.machinelearning-targets.cmake`) which defines the IMPORTED
102+
targets.
103+
104+
The same targets (`WindowsML::WindowsML`, `WindowsML::Api`, `WindowsML::OnnxRuntime`, `WindowsML::DirectML`) are available
105+
in both consumption modes. Use the standard CMake 3.21 `$<TARGET_RUNTIME_DLLS>` generator expression
106+
to copy runtime DLLs to the build output directory.
107+
46108
### [Python](#tab/python)
47109

48110
The Python binding leverages the [pywinrt](https://github.com/pywinrt/pywinrt) project for the Windows App SDK projection. Ensure that your Python installation is not from the Microsoft Store (you can install an unpackaged version from python.org or via winget). The sample depends on using the Windows App SDK dynamic dependency API, which is only valid for unpackaged apps.
@@ -58,10 +120,10 @@ Please make sure the `wasdk-` packages' version matches the WindowsAppRuntime's
58120

59121
## Step 2: Download and register EPs
60122

61-
The simplest way to get started is to let Windows ML automatically discover, download, and register the latest version of all compatible execution providers. Execution providers need to be registered with the ONNX Runtime inside of Windows ML before you can use them. And if they haven't been downloaded yet, they need to be downloaded first. Calling `EnsureAndRegisterCertifiedAsync()` will do both of these in one step.
62-
63123
### [C#](#tab/csharp)
64124

125+
The simplest way to get started is to let Windows ML automatically discover, download, and register the latest version of all compatible execution providers. Execution providers need to be registered with the ONNX Runtime inside of Windows ML before you can use them. And if they haven't been downloaded yet, they need to be downloaded first. Calling `EnsureAndRegisterCertifiedAsync()` will do both of these in one step.
126+
65127
```csharp
66128
using Microsoft.ML.OnnxRuntime;
67129
using Microsoft.Windows.AI.MachineLearning;
@@ -84,7 +146,9 @@ var catalog = ExecutionProviderCatalog.GetDefault();
84146
await catalog.EnsureAndRegisterCertifiedAsync();
85147
```
86148

87-
### [C++](#tab/cppwinrt)
149+
### [C++/WinRT](#tab/cppwinrt)
150+
151+
The simplest way to get started is to let Windows ML automatically discover, download, and register the latest version of all compatible execution providers. Execution providers need to be registered with the ONNX Runtime inside of Windows ML before you can use them. And if they haven't been downloaded yet, they need to be downloaded first. Calling `EnsureAndRegisterCertifiedAsync()` will do both of these in one step.
88152

89153
```cppwinrt
90154
#include <winrt/Microsoft.Windows.AI.MachineLearning.h>
@@ -101,8 +165,55 @@ winrt::Microsoft::Windows::AI::MachineLearning::ExecutionProviderCatalog catalog
101165
catalog.EnsureAndRegisterCertifiedAsync().get();
102166
```
103167

168+
### [C/C++](#tab/c)
169+
170+
With the C APIs, you must download a specific execution provider, and then manually register its path with ONNX Runtime.
171+
172+
```cpp
173+
#include <WinMLEpCatalog.h>
174+
#include <onnxruntime_cxx_api.h> // Or <onnxruntime_c_api.h> if just using C
175+
#include <filesystem>
176+
#include <string>
177+
178+
// Initialize ONNX Runtime
179+
Ort::Env env(ORT_LOGGING_LEVEL_ERROR, "WinMLDemo"); // Use an ID of your own choice
180+
181+
// --- Windows ML: Get EP catalog handle ---
182+
WinMLEpCatalogHandle catalog = nullptr;
183+
HRESULT hr = WinMLEpCatalogCreate(&catalog);
184+
if (FAILED(hr))
185+
{
186+
// Handle error
187+
return;
188+
}
189+
190+
// --- Windows ML: Find, download, and register a specific EP (in this case, QNN) ---
191+
WinMLEpHandle ep = nullptr;
192+
hr = WinMLEpCatalogFindProvider(catalog, "QNN", NULL, &ep);
193+
if (SUCCEEDED(hr))
194+
{
195+
// Windows ML: Download the EP if it isn't already downloaded
196+
WinMLEpEnsureReady(ep);
197+
198+
// Windows ML: Get the EP library path
199+
size_t pathSize = 0;
200+
WinMLEpGetLibraryPathSize(ep, &pathSize);
201+
std::string libraryPathUtf8(pathSize, '\0');
202+
WinMLEpGetLibraryPath(ep, pathSize, libraryPathUtf8.data(), nullptr);
203+
204+
// Register the EP with ONNX Runtime using the C++ API
205+
std::filesystem::path libraryPath(libraryPathUtf8);
206+
env.RegisterExecutionProviderLibrary("QNN", libraryPath.wstring());
207+
}
208+
209+
// --- Windows ML: Release the EP catalog handle ---
210+
WinMLEpCatalogRelease(catalog);
211+
```
212+
104213
### [Python](#tab/python)
105214
215+
With the Python APIs, you can enumerate all compatible execution providers, and then manually register their paths with ONNX Runtime.
216+
106217
```python
107218
import sys
108219
from pathlib import Path

0 commit comments

Comments
 (0)