Microsoft store UWP App

DotNET Fan 191 Reputation points
2024-03-04T13:40:27.6733333+00:00

Hello UWP experts,

How can we identify from the UWP code that the user has installed from the Microsoft store or from the sideload packages or dev build process from VS?

Thanks

Windows 10
Windows 10
A Microsoft operating system that runs on personal computers and tablets.
10,619 questions
Universal Windows Platform (UWP)
Windows 11
Windows 11
A Microsoft operating system designed for productivity, creativity, and ease of use.
8,168 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Wesley Li 4,815 Reputation points
    2024-03-05T02:40:41.8333333+00:00

    Hello

    Determining the source of a UWP app installation (Microsoft Store, sideload, or Visual Studio) directly from within the app can be challenging because the app’s code doesn’t inherently know where it was installed from. However, there are some indirect methods you could consider:

     

    App Version or Package Name: You could use different version numbers or package names for the Store version and the sideload/dev build. Then, in your code, you can check the app’s version or package name using Windows.ApplicationModel.Package.Current.Id.Version or Windows.ApplicationModel.Package.Current.Id.Name respectively.

     

    Compilation Symbols: You can define different compilation symbols for different build configurations in Visual Studio. For example, you might have a symbol like STORE defined for the Store build configuration, and check for this symbol in your code.

     

    App Services: If your app communicates with a server, you could potentially have the app send some information about its installation when it first runs or at certain intervals. This would require user consent for privacy reasons.

     

    Telemetry Data: If your app uses a telemetry service like Microsoft App Center or Google Analytics, you could send custom events to track from where the app was installed. This would also require user consent.

     

    These methods can give you clues about the installation source, but they aren’t foolproof. A tech-savvy user could sideload an app package obtained from the Store, or modify the package name or version of a sideloaded app, for example. Always consider the privacy implications and get user consent if you’re collecting or transmitting any data. If you need a foolproof method, you may need to consider other options, such as licensing your software.

    Best Regards,

    Wesley Li

    1 person found this answer helpful.
    0 comments No comments

  2. Junjie Zhu - MSFT 14,831 Reputation points Microsoft Vendor
    2024-03-05T03:49:49.3533333+00:00

    Hi @DotNET Fan

    Welcome to Microsoft Q&A!

    It is easy to distinguish between installing from VS or msix packages. You only need to analyze the current InstalledLocation.

    Your InstalledLocation for deploying from VS will be in the project file APPX, and the InstalledLocation for installing from msix packages will be in C:\Program Files\WindowsApps. But there is no way to distinguish between the store and the sideload. because their paths are the same.

    string Path = Windows.ApplicationModel.Package.Current.InstalledLocation.Path;
    

    Thank you.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.