You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

.NET MAUI 8.0 RC2 Windows发布报错求助:Manifest验证失败

.NET MAUI 8 RC2 Windows Release单文件发布报错:Manifest中声明的EXE不存在

问题场景

升级.NET MAUI应用至8.0.0-rc.2.9373版本后,执行Windows平台Release发布命令:

dotnet publish project.csproj -f net8.0-windows10.0.19041.0 -c Release /p:RuntimeIdentifierOverride=win10-x64 -p:PublishSingleFile=true -o C:\Users\admin\Documents\publish

触发以下MakeAppx报错:

MakeAppx : error : Manifest validation error: Line 25, Column 27, Reason: The file name "Project.exe" declared for the element "*[local-name()='Applications']/*[local-name()='Application']"
doesn't exist in the package. [C:\Users\admin\Documents\Work\Project\ProjectSolution\Project\project.csproj::TargetFramework=net8.0-windows10.0.19041.0]
MakeAppx : error : Package creation failed. [C:\Users\admin\Documents\Work\Project\ProjectSolution\Project\project.csproj::TargetFramework=net8.0-windows10.0.19041.0]
MakeAppx : error : 0x80080204 - The specified package format is not valid: The package manifest is not valid. [C:\Users\admin\Documents\Work\Project\ProjectSolution\Project\project.csproj
::TargetFramework=net8.0-windows10.0.19041.0]

切换为Debug构建(-c Debug)则一切正常。

解决方案

1. 修正项目文件的单文件发布配置

在项目的.csproj文件中,针对Release模式添加明确的单文件发布配置,确保打包流程能识别单文件输出:

<PropertyGroup Condition="'$(Configuration)' == 'Release'">
  <PublishSingleFile>true</PublishSingleFile>
  <SelfContained>true</SelfContained>
  <IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
  <WindowsAppSDKSelfContained>true</WindowsAppSDKSelfContained>
  <RuntimeIdentifier>win10-x64</RuntimeIdentifier>
</PropertyGroup>

这样可以避免命令行参数和项目配置冲突,让构建流程统一处理单文件发布逻辑。

2. 调整发布命令参数

移除RuntimeIdentifierOverride,改用标准的-r参数指定运行时标识符,RC2版本对RuntimeIdentifierOverride的处理可能存在兼容性问题:

dotnet publish project.csproj -f net8.0-windows10.0.19041.0 -c Release -r win10-x64 -p:PublishSingleFile=true -o C:\Users\admin\Documents\publish

3. 检查Package.appxmanifest的Executable配置

打开项目中的Package.appxmanifest,确保Application节点的Executable属性使用变量而非硬编码文件名,让构建时自动替换为实际输出的单文件EXE:

<Application Id="App" Executable="$targetnametoken$.exe" EntryPoint="Project.App">

如果当前是硬编码的Project.exe,替换为$targetnametoken$.exe即可适配单文件发布后的文件名变化。

4. 清理缓存后重新构建

执行以下命令清理项目缓存,再重新发布,避免旧文件干扰:

dotnet clean project.csproj -c Release
rmdir /s /q C:\Users\admin\Documents\publish

之后重新运行发布命令。

原因说明

Debug模式下,单文件发布默认不会完全合并依赖,原始的Project.exe会保留在输出目录中,因此Manifest能找到对应文件;而Release模式下,单文件发布会将所有依赖合并到单个EXE中,原始的Project.exe会被移除或路径改变,导致MakeAppx打包时无法匹配Manifest中声明的文件路径。

内容的提问来源于stack exchange,提问作者Guzun Ion

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.01 00:08:27