Update app from code

Halifax Crosby 80 Reputation points
2025-12-02T13:27:03.8766667+00:00

Hello

https://learn.microsoft.com/en-us/windows/msix/store-developer-package-update

Is it possible to check if an update is available, and download/install it in .Net Framework WinForms apps? (full trust store packaged)

Thanks in advance.

Windows development | Windows API - Win32
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Michael Le (WICLOUD CORPORATION) 6,020 Reputation points Microsoft External Staff Moderator
    2025-12-03T11:00:32.31+00:00

    Hello @Halifax Crosby ,

    Yes—this is supported when your WinForms app is MSIX‑packaged and runs with package identity (installed from the Microsoft Store or sideloaded as MSIX). Use the WinRT Windows.Services.Store APIs, specifically StoreContext, to check for updates, download them, and then let Windows prompt the user to install.

    What you need

    • MSIX packaging.
    • Add Microsoft.Windows.SDK.Contracts (NuGet) so your .NET Framework app can call WinRT APIs.
    • Target Windows 10, version 1607 (build 14393) or later (recommend 1809+).
    • In desktop apps, initialize StoreContext with your window handle and call update methods on the UI thread.

    A minimal flow should look like this

    using Windows.Services.Store;
    using WinRT.Interop; // InitializeWithWindow, WindowNative
    
    // e.g., inside your main Form
    private StoreContext _store;
    
    protected override void OnHandleCreated(EventArgs e)
    {
        base.OnHandleCreated(e);
        _store = StoreContext.GetDefault();
        InitializeWithWindow.Initialize(_store, WindowNative.GetWindowHandle(this)); // bind UI
    }
    
    private async void btnUpdate_Click(object sender, EventArgs e)
    {
        var updates = await _store.GetAppAndOptionalStorePackageUpdatesAsync();
        if (updates.Count == 0)
        {
            MessageBox.Show("No updates available.");
            return;
        }
    
        // Optional: background download first
        // await _store.RequestDownloadStorePackageUpdatesAsync(updates).AsTask();
    
        // Save state, then request install (Windows shows a consent dialog)
        var result = await _store.RequestDownloadAndInstallStorePackageUpdatesAsync(updates).AsTask();
        // The app will normally close for install. Inspect result.OverallState for status.
    }
    

    Restart behavior

    • Updates typically close your app to install. If you need it to relaunch automatically, call RegisterApplicationRestart before triggering install.

    I hope this helps.

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.