Add Windows App SDK To WPF Or WinForms
Use this path when an existing desktop app needs a modern Windows API and a rewrite would slow shipping.
Steps
- Add the
Microsoft.WindowsAppSDKNuGet package from Visual Studio or the current official CLI path. - Choose deployment model: packaged, external-location, or unpackaged.
- If unpackaged or external-location, initialize the Windows App SDK runtime before using SDK APIs.
- For window-bound APIs, get the HWND and use the documented interop path.
- Test in the real deployment model, not just from the IDE.
Example Boundary
public sealed class WindowInteropService
{
public IntPtr GetHwnd(Window window)
{
return new System.Windows.Interop.WindowInteropHelper(window).Handle;
}
}
Keep this in infrastructure code. Do not make view models depend on HWNDs.
When To Stop
Stop and redesign if the feature assumes package identity but the existing app remains unpackaged with no identity plan.