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

  1. Add the Microsoft.WindowsAppSDK NuGet package from Visual Studio or the current official CLI path.
  2. Choose deployment model: packaged, external-location, or unpackaged.
  3. If unpackaged or external-location, initialize the Windows App SDK runtime before using SDK APIs.
  4. For window-bound APIs, get the HWND and use the documented interop path.
  5. 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.