1

I have a UWP app in the Microsoft Store, and I would like to install the store version and my local development version side-by-side.

I can achieve this manually by updating the Name fields in the Package.appxmanifest, but I am after a solution to automate this so its less error prone (I don't want to forget to change the name back to the "Release" version when I submit to the Store).

Is there a way to use the build configurations to automate this for me? To have a different package name in Debug builds compared to release builds?

Josh Hunt
  • 14,225
  • 26
  • 79
  • 98

3 Answers3

3

Install Debug and Release builds of UWP app side-by-side

Currently, UWP does not support install apps with same Package Family Name, if you want to install debug version, you need edit the Package Family Name for the project as mentioned above.

For your requirement, you could make debug branch and release branch with different PFN. you could post your code into debug branch and build local debug app, when you want to publish the new version to the store. please merge debug branch to the release branch and keep release Package Family Name.

Nico Zhu
  • 32,367
  • 2
  • 15
  • 36
1

You can do this using a build pipeline that changes the name in the manifest and then publishes the app to the store. Once you have a pipeline setup you can add a step that changes the name. Keep in mind this step will change the app name to the correct one you want in the Store. In order to run them side by side, you will need to change the name in the manifest to the dev name.

- task: PowerShell@2
  inputs:
    targetType: 'inline'
    script: |
      [xml]$xmlDoc = Get-Content $(Build.SourcesDirectory)\Package.appxmanifest
      $xmlDoc.Package.Identity.Name="PackageName"
      $xmlDoc.Package.Properties.DisplayName="AppName"
      $xmlDoc.Package.Applications.Application.VisualElements.DisplayName="AppName"
      $xmlDoc.Save('$(Build.SourcesDirectory)\Package.appxmanifest')
    failOnStderr: true
0

If you don't mind making your .appxmanifest slightly harder to modify in the visual editor, you can turn it into a T4 Template, and regenerate your manifest before each build with an extra csproj parameter.

That allows you to make your appxmanifest change depending on your build configuration, so you can have a different Package Identity for both Debug and Release.

Modifications to Package.appxmanifest (renamed to Package.tt)

<#@ template hostspecific="true" language="C#" #>
<#@ output extension=".appxmanifest" #>
<#@ parameter type="System.String" name="BuildConfiguration" #>
<#  
    string version = "1.4.1.0";
    
    // Get configuration name at Build time
    string configName = Host.ResolveParameterValue("-", "-", "BuildConfiguration");
    if (string.IsNullOrWhiteSpace(configName))
    {
        // Default to Debug at Design Time.
        configName = "Debug";
    }
#>
<?xml version="1.0" encoding="utf-8"?> 
    
<Package
  xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
  xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest"
  xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
  xmlns:uap5="http://schemas.microsoft.com/appx/manifest/uap/windows10/5"
  xmlns:genTemplate="http://schemas.microsoft.com/appx/developer/windowsTemplateStudio"
  xmlns:uap3="http://schemas.microsoft.com/appx/manifest/uap/windows10/3"
  IgnorableNamespaces="uap mp genTemplate uap3">

<# 
    if (configName == "Debug") 
    {
#><Identity 
    Name="MyAppDebugIdentity"
    Publisher="MyDebugPublisher"
    Version="<#=version#>" />
<#
    }
    else
    {
#><Identity
    Name="MyAppIdentityName"
    Publisher="CN=blerb"
    Version="<#=version#>" />
<#
    }
#>

<!-- The rest of your package.appxmanifest file goes here -->

Add the following to your .csproj:

  <PropertyGroup>
    <!-- This is what will cause the templates to be transformed when the project is built (default is false) -->
    <TransformOnBuild>true</TransformOnBuild>
    <!-- Set to true to force overwriting of read-only output files, e.g. if they're not checked out (default is false) -->
    <OverwriteReadOnlyOutputFiles>true</OverwriteReadOnlyOutputFiles>
    <!-- Set to false to transform files even if the output appears to be up-to-date (default is true)  -->
    <TransformOutOfDateOnly>false</TransformOutOfDateOnly>
  </PropertyGroup>
  <ItemGroup>
    <T4ParameterValues Include="BuildConfiguration">
      <Value>$(Configuration)</Value>
      <Visible>false</Visible>    
    </T4ParameterValues>
  </ItemGroup>
  <Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TextTemplating\Microsoft.TextTemplating.targets" />

This setup only works at Build time and will default to the debug identity otherwise: You can improve it somewhat by including EnvDte parsing in the template, but I didn't feel that was really needed here.

Difegue
  • 1
  • 2