【问题标题】:Install Debug and Release builds of UWP app side-by-side并排安装 UWP 应用的调试和发布版本
【发布时间】:2020-07-29 12:20:55
【问题描述】:

我在 Microsoft Store 中有一个 UWP 应用,我想同时安装商店版本和我的本地开发版本。

我可以通过更新 Package.appxmanifest 中的 Name 字段来手动实现这一点,但我正在寻求一个自动化的解决方案,这样它就不容易出错(我不想忘记将名称改回“Release " 提交到商店时的版本)。

有没有办法使用构建配置为我自动执行此操作?与发布版本相比,在调试版本中使用不同的包名称?

【问题讨论】:

  • 你想解决什么问题?

标签: visual-studio uwp


【解决方案1】:

并排安装 UWP 应用的调试和发布版本

目前,UWP 不支持安装具有相同 Package Family Name 的应用程序,如果要安装调试版本,则需要按照上述方法编辑项目的 Package Family Name。

根据您的要求,您可以使用不同的 PFN 创建调试分支和发布分支。当您想将新版本发布到商店时,您可以将代码发布到调试分支并构建本地调试应用程序。请将调试分支合并到发布分支并保留发布包系列名称。

【讨论】:

    【解决方案2】:

    您可以使用构建管道来执行此操作,该管道更改清单中的名称,然后将应用发布到商店。完成管道设置后,您可以添加一个更改名称的步骤。请记住,此步骤会将应用程序名称更改为您在商店中想要的正确名称。为了并排运行它们,您需要将清单中的名称更改为开发名称。

    - 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
    

    【讨论】:

      【解决方案3】:

      如果您不介意让您的 .appxmanifest 在可视化编辑器中稍微难以修改,您可以将其转换为 T4 模板,并在每次构建之前使用额外的 csproj 参数重新生成您的清单。

      这允许您根据构建配置更改 appxmanifest,因此您可以为调试和发布使用不同的包标识。

      对 Package.appxmanifest 的修改(重命名为 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 -->
      

      将以下内容添加到您的 .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" />
      
      

      此设置仅在构建时有效,否则将默认为调试标识:您可以通过在模板中包含 EnvDte 解析来对其进行一些改进,但我觉得这里并不需要这样做。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-07-23
        • 2017-01-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-11-13
        相关资源
        最近更新 更多