|
| 1 | +--- |
| 2 | +title: Grant package identity by packaging with external location in Visual Studio |
| 3 | +description: How to use Visual Studio to grant package identity to an unpackaged Win32 app so that you can use modern Windows features in that app. |
| 4 | +ms.date: 05/09/2025 |
| 5 | +ms.topic: article |
| 6 | +keywords: windows 11, windows 10, desktop, sparse, package, identity, external, location, MSIX, Win32, Visual Studio |
| 7 | +ms.localizationpriority: medium |
| 8 | +--- |
| 9 | + |
| 10 | +# Grant package identity by packaging with external location in Visual Studio |
| 11 | + |
| 12 | +Many Windows features can be used by a desktop app only if that app has package identity at runtime. See [Features that require package identity](/windows/apps/desktop/modernize/modernize-packaged-apps). If you have an existing desktop app, with its own installer, then there's very little you need to change in order to benefit from package identity. |
| 13 | + |
| 14 | +Starting in Windows 10, version 2004, you can grant package identity to an app simply by building and registering a *package with external location* with your app. Packaging with external location allows you to register a simple identity package in your existing installer without changing how or where you install your application. You might be familiar with full MSIX packaging; this is a much lighter-weight option, as described below. |
| 15 | + |
| 16 | +If you already have a Visual Studio project for your application, then building an identity package in Visual Studio provides a more streamlined experience than [building an identity package manually](/windows/apps/desktop/modernize/grant-identity-to-nonpackaged-apps). |
| 17 | + |
| 18 | +These are the steps that we'll be describing in detail in this topic to build and register an identity package using Visual Studio: |
| 19 | + |
| 20 | +1. [Install Visual Studio components](#install-visual-studio-components) |
| 21 | +2. [Add a Packaging Project to your solution](#add-a-packaging-project-to-your-solution) |
| 22 | +3. [Configure the Packaging Project for signing](#configure-the-packaging-project-for-signing) |
| 23 | +4. [Build and test the Packaging Project in Release Mode](#build-and-test-the-packaging-project-in-release-mode) |
| 24 | +5. [Register the identity package in your installer](#register-the-identity-package-in-your-installer) |
| 25 | + |
| 26 | +## Install Visual Studio components |
| 27 | + |
| 28 | +Creating an identity package in Visual Studio requires the **Windows Application Packaging Project** and the **Package with External Location** extension. |
| 29 | + |
| 30 | +Install the **Windows Application Packaging Project** components as described in [Required Visual Studio version and workload](/windows/msix/desktop/desktop-to-uwp-packaging-dot-net#required-visual-studio-version-and-workload). |
| 31 | + |
| 32 | +In Visual Studio, via the **Extensions** > **Manage Extensions** menu item, install the **Package with External Location** extension. |
| 33 | + |
| 34 | +## Add a Packaging Project to your solution |
| 35 | + |
| 36 | +To add a Packaging Project to your solution with a Project Reference to your application project, see [Set up the Windows Application Packaging Project in your solution](/windows/msix/desktop/desktop-to-uwp-packaging-dot-net#set-up-the-windows-application-packaging-project-in-your-solution). |
| 37 | + |
| 38 | +Enable packaging with external location by right-clicking the Packaging Project in Solution Explorer, navigating to the **External Location** tab provided by the **Package with External Location** extension, enabling the **Package with External Location** option, and saving the changes. |
| 39 | + |
| 40 | +Set the **Package name** and **Publisher display name** fields of the identity package by double-clicking `Package.appxmanifest` in the Packaging Project to open the visual manifest editor, navigating to the Packaging tab, and setting the **Package name** and **Publisher display name** fields to the desired values. |
| 41 | + |
| 42 | +If you have a custom application manifest in your application project, then for info about synchronizing the values with the values from `Package.appxmanifest`, see [Add identity metadata to your desktop application manifests](/windows/apps/desktop/modernize/grant-identity-to-nonpackaged-apps#add-identity-metadata-to-your-desktop-application-manifests). The **Package with External Location** extension uses **App** for the **applicationId**. |
| 43 | + |
| 44 | +If you don't have a custom application manifest, then Visual Studio will produce the appropriate artifacts during the build process. .NET projects embed a manifest by default, which conflicts with the produced manifest artifacts. To resolve that, right-click the Project, open **Properties**, and in the **Application** tab under the **Manifest** section, change **Embed manifest with default settings** to **Create application without a manifest**. |
| 45 | + |
| 46 | +## Configure the Packaging Project for signing |
| 47 | + |
| 48 | +Generate a certificate for signing by walking through the **Publish** > **Create App Packages** wizard shown in [Create an app package using the packaging wizard](/windows/msix/package/packaging-uwp-apps#create-an-app-package-using-the-packaging-wizard). |
| 49 | + |
| 50 | +On the first screen, ensure that **Sideloading** is selected, and **Enable automatic updates** is unchecked. On the second screen, create a self-signed certificate if necessary, then click the **Trust** button to trust it in the Local Machine Trusted People certificate store. On the final screen, set **Generate app bundle** to *Never*, and click **Create** to complete the signing configuration. |
| 51 | + |
| 52 | +## Build and test the Packaging Project in Release Mode |
| 53 | + |
| 54 | +To avoid complications from Debug mode dependencies, set the Build configuration to Release mode, and build the Packaging Project. |
| 55 | + |
| 56 | +Building the Packaging Project produces a **PackageWithExternalLocation** folder in the build output. That folder contains the `MSIX` file representing the identity package, as well as `Install` and `Remove` PowerShell scripts to register and unregister the generated identity package locally for testing. |
| 57 | + |
| 58 | +The `Install` PowerShell script registers the generated identity package locally, and connects it with the `ExternalLocation` sibling folder for testing purposes. To test the application with identity, run the application executable from the `ExternalLocation` folder. |
| 59 | + |
| 60 | +To associate identity with your application in production, you'll need to ship the generated identity package with your application, and register it in your installer. |
| 61 | + |
| 62 | +## Register the identity package in your installer |
| 63 | + |
| 64 | +The last step to associate identity with your application is to register the identity package in your installer, and associate it with your application's installation directory. |
| 65 | + |
| 66 | +The code listing below demonstrates registering the identity package by using the [**PackageManager.AddPackageByUriAsync**](/uwp/api/windows.management.deployment.packagemanager.addpackagebyuriasync) method. |
| 67 | + |
| 68 | +```csharp |
| 69 | +using Windows.Management.Deployment; |
| 70 | + |
| 71 | +... |
| 72 | + |
| 73 | +var externalUri = new Uri(externalLocation); |
| 74 | +var packageUri = new Uri(packagePath); |
| 75 | + |
| 76 | +var packageManager = new PackageManager(); |
| 77 | + |
| 78 | +var options = new AddPackageOptions(); |
| 79 | +options.ExternalLocationUri = externalUri; |
| 80 | + |
| 81 | +await packageManager.AddPackageByUriAsync(packageUri, options); |
| 82 | +``` |
| 83 | + |
| 84 | +Be aware of the following important details about this code: |
| 85 | +* Set `externalLocation` to the absolute path of your application's installation directory (without any executable names). |
| 86 | +* Set `packagePath` to the absolute path of the identity package produced in the previous step (with the file name). |
| 87 | + |
| 88 | +For production-ready code in C# and C++, see [Sample apps](#sample-apps) below. The samples also demonstrate how to unregister the identity package on uninstall. |
| 89 | + |
| 90 | +## Sample apps |
| 91 | + |
| 92 | +For fully functional C# and C++ apps that demonstrate how to register an identity package, see the [PackageWithExternalLocation](https://aka.ms/sparsepkgsample) samples. |
0 commit comments