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

如何在Visual Studio 2022 17.4及以上版本发布仅Windows的MAUI应用?

单Windows TargetFramework的MAUI项目在VS2022 17.4+发布问题解决办法

问题说明

  • 项目仅配置Windows作为TargetFramework,VS2022 17.4版本前可通过pubxml正常发布
  • 升级到17.4后,GUI发布失败,提示仅多平台TargetFrameworks配置才会加载pubxml;命令行发布必须额外添加Android作为TargetFramework才能执行

可行解决方案

方案1:命令行直接指定参数(无需添加额外平台)

不用添加Android平台,直接在命令行指定Windows的TargetFramework、RuntimeIdentifier和pubxml文件:

dotnet publish -f net7.0-windows10.0.19041.0 -r win10-x64 /p:PublishProfile=YourPublishProfile.pubxml

注意:替换net7.0-windows10.0.19041.0为项目实际使用的Windows TargetFramework版本,YourPublishProfile.pubxml为你的发布配置文件名

方案2:修改项目文件,启用单平台GUI发布支持

在项目的.csproj文件中添加以下属性,强制让单TargetFramework项目支持pubxml发布:

<PropertyGroup>
  <IsPublishProfileSupported>true</IsPublishProfileSupported>
</PropertyGroup>

添加后重新加载项目,即可在VS GUI中正常选择pubxml完成发布。

方案3:项目文件嵌入发布配置(替代pubxml)

如果不想单独维护pubxml文件,可以把发布参数直接写进项目文件的Release配置段:

<PropertyGroup Condition="'$(Configuration)' == 'Release'">
  <RuntimeIdentifier>win10-x64</RuntimeIdentifier>
  <PublishSingleFile>true</PublishSingleFile>
  <SelfContained>true</SelfContained>
  <PublishReadyToRun>true</PublishReadyToRun>
  <!-- 根据需求添加其他发布参数,比如输出目录、压缩设置等 -->
</PropertyGroup>

之后直接通过VS的Release配置发布即可,无需依赖pubxml文件。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.11 11:15:33