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