Search code examples
c#wpfclickoncedesktop-bridgemsix

Detecting MSIX packaged application at runtime


I have WPF application packaged as MSIX but the same code can also be packaged as ClickOnce or working without any package as portable. What would be the best way to detect at runtime which packaging technology (if any) is used?

EDIT: I will try to clarify things a little bit since question is getting downvotes without any comment. Existing app is packaged as ClickOnce. We're trying to move it to MSIX which seams to be working just fine, but not whole user base will be migrated at once and we need compatibility with older packaging format too since "modern" way of packaging introduces a lot of limitations which should be handled differently.


Solution

  • Yes, you can use Windows.ApplicationModel.Package.Current to see if you are running as a packaged app. Assuming you're using C# (but you can use C++ etc. as well):

    internal static bool IsPackaged()
    {
      try
      {
        // If we have a package ID then we are running in a packaged context
        var dummy = Windows.ApplicationModel.Package.Current.Id;
        return true;
      }
      catch
      {
        return false;
      }
    }
    

    (From this Desktop Bridge sample).