如何编写Package.appxmanifest在Windows Server 2019安装Windows服务
我有如下Package.appxmanifest文件:
<?xml version="1.0" encoding="utf-8"?> <Package xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10" xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10" xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities" xmlns:desktop6="http://schemas.microsoft.com/appx/manifest/desktop/windows10/6" IgnorableNamespaces="uap rescap"> <Identity Name="fac86114-6581-44d8-af9c-29c854873a79" Publisher="CN=E=contact@proreception.com, Pro Reception ApS, O=Pro Reception ApS, L=Kongens Lyngby, S=Hovedstaden, C=DK" Version="0.0.2.0" /> <Properties> <DisplayName>Pro Reception Print Server</DisplayName> <PublisherDisplayName>Pro Reception</PublisherDisplayName> <Logo>Images\StoreLogo.png</Logo> </Properties> <Dependencies> <TargetDeviceFamily Name="Windows.Universal" MinVersion="10.0.0.0" MaxVersionTested="10.0.0.0" /> <TargetDeviceFamily Name="Windows.Desktop" MinVersion="10.0.14393.0" MaxVersionTested="10.0.14393.0" /> </Dependencies> <Resources> <Resource Language="x-generate"/> </Resources> <Applications> <Application Id="App" Executable="$targetnametoken$.exe" EntryPoint="$targetentrypoint$"> <uap:VisualElements DisplayName="Pro Reception Print Server" Description="This service is needed for printing visitor name tags" BackgroundColor="transparent" Square150x150Logo="Images\Square150x150Logo.png" Square44x44Logo="Images\Square44x44Logo.png"> <uap:DefaultTile Wide310x150Logo="Images\Wide310x150Logo.png" /> <uap:SplashScreen Image="Images\SplashScreen.png" /> </uap:VisualElements> <Extensions> <desktop6:Extension Category="windows.service" Executable="ProReception.PrintServer\ProReception.PrintServer.exe" EntryPoint="Windows.FullTrustApplication"> <desktop6:Service Name="Pro Reception Print Server" StartupType="auto" StartAccount="localService"> </desktop6:Service> </desktop6:Extension> </Extensions> </Application> </Applications> <Capabilities> <Capability Name="internetClient" /> <rescap:Capability Name="runFullTrust" /> <rescap:Capability Name="packagedServices"/> </Capabilities> </Package>
该应用可在Windows 10机器上成功安装,但在Windows Server 2019机器上安装失败,报错:
error 0xC00CE014: App manifest validation error: The app manifest must be valid as per schema: Line 26, Column 10, Note: The schema for MaxVersionTested specified does not recognize XML fields with namespace "http://schemas.microsoft.com/appx/manifest/desktop/windows10/6". Please ensure that you have the correct MaxVersionTested specified. Reason: Element '{http://schemas.microsoft.com/appx/manifest/desktop/windows10/6}Extension' is unexpected according to content model of parent element '{http://schemas.microsoft.com/appx/manifest/foundation/windows10}Extensions'. Expecting: {http://schemas.microsoft.com/appx/manifest/foundation/windows10}Appl icationExtensionChoice, {http://schemas.microsoft.com/appx/manifest/foundation/w indows10}ExtensionChoice
我不太理解该错误,但似乎desktop6命名空间在Windows Server 2019上不受支持。情况是否属实?若是,应如何调整安装程序以在Windows Server 2019机器上安装我的应用?
解答
关于desktop6命名空间的支持情况
是的,desktop6命名空间对应的功能(比如你用到的windows.service打包服务扩展)在Windows Server 2019上确实不受官方支持。Windows Server 2019对应的Windows 10内核版本是1809(内部版本17763),而desktop6命名空间是在Windows 10 2004(内部版本19041)及以上才引入的桌面扩展能力,Server 2019的系统版本低于这个要求,因此会触发manifest验证错误。
可行的调整方案
方案1:改用传统Windows服务部署
由于Server 2019不支持UWP打包式服务,你需要将打印服务改为独立的传统Windows服务:
- 将
ProReception.PrintServer.exe编译为标准Windows服务(可通过.NET的ServiceBase类实现) - 使用系统命令
sc create编写安装脚本,手动注册并启动服务 - 若需保留原UWP应用的其他功能,可通过进程间通信(如命名管道、TCP套接字)实现UWP应用与独立服务的交互
方案2:升级服务器到Windows Server 2022
Windows Server 2022对应Windows 10 21H2版本,完全支持desktop6命名空间及打包服务功能。如果你的环境允许升级服务器系统,这是最无需修改代码的解决方案。
方案3:临时绕过验证(仅测试用,不推荐生产)
如果只是需要让应用在Server 2019上安装成功(服务功能会失效),可以修改manifest绕过验证:
- 在
Package节点的IgnorableNamespaces中添加desktop6:
IgnorableNamespaces="uap rescap desktop6"
- 将
Windows.Desktop的MaxVersionTested改为Server 2019对应的版本:
<TargetDeviceFamily Name="Windows.Desktop" MinVersion="10.0.14393.0" MaxVersionTested="10.0.17763.0" />
注意:这种方法仅能通过安装验证,打印服务不会在Server 2019上运行,仅适合测试场景。
内容的提问来源于stack exchange,提问作者Søren Pedersen

