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

时间:2020-07-29 12:20:55

标签: visual-studio uwp

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

我可以通过更新Package.appxmanifest中的“名称”字段来手动实现此目的,但是我正在寻找一种解决方案来实现此目的的自动化,因此它的错误发生率较小(我不想忘记将名称更改回“发布” ”提交给商店时的版本。

有没有一种方法可以使用构建配置自动执行此操作?要使Debug版本中的软件包名称与发布版本中的软件包名称不同?

3 个答案:

答案 0 :(得分:2)

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

当前,UWP不支持使用具有相同软件包家族名称的安装应用程序,如果要安装调试版本,则需要如上所述编辑项目的软件包家族名称。

根据您的要求,您可以使用不同的PFN进行debug分支和release分支。当您要将新版本发布到商店时,可以将代码发布到debug分支并构建本地调试应用。请将debug分支合并到release分支,并保留发布的Package Family Name。

答案 1 :(得分:1)

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

class PlayerPreferences extends StatefulWidget {
  final int numPlayers;
  PlayerPreferences({this.numPlayers});

  @override
  _PlayerPreferencesState createState() => _PlayerPreferencesState();
}

class _PlayerPreferencesState extends State<PlayerPreferences> {
  int dropDownValue = 0;
  @override
  Widget build(BuildContext context) {
    return Container(
      child: DropdownButton(
        value: dropDownValue,
        onChanged: (int newVal){
          setState(() {
            dropDownValue = newVal;
          });
        },
        items: [
          DropdownMenuItem(
            value: 0,
            child: Text('Yellow'),
          ),
          DropdownMenuItem(
            value: 1,
            child: Text('Red'),
          ),
          DropdownMenuItem(
            value: 2,
            child: Text('Blue'),
          ),
          DropdownMenuItem(
            value: 3,
            child: Text('Green'),
          ),
        ],
      ),
    );
  }
}

答案 2 :(得分:0)

如果您不介意让您的 .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 解析来稍微改进它,但我觉得这里并不需要这样做。

>
相关问题