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

C# MAUI Windows应用发布至其他Windows设备遇错求助

C# MAUI Windows应用部署问题解决

问题背景

使用Visual Studio Community 2022(v17.6.5)开发的C# MAUI Windows应用,在开发机及测试移动设备运行正常,尝试发布到另一台Windows机器时,按官方步骤操作出现两次报错:

第一次发布报错

1>------ Publish started: Project: Studio Sign-In 202307, Configuration: Debug Any CPU ------
1>Determining projects to restore...
1>All projects are up-to-date for restore.
1>Unable to determine the Android ABI from the value 'win10-x86'. Edit the project file in a text editor and set the 'RuntimeIdentifiers' MSBuild property to contain only valid identifiers for the Android platform.
========== Publish: 0 succeeded, 1 failed, 0 skipped ==========
========== Publish started at 2:27 PM and took 02.079 seconds ==========
========== Package: 0 succeeded, 1 failed ===========

更新操作后新报错

移除Android和iOS目标后,发布仍失败,错误信息:

1>Studio Sign-In 202307 -> E:\Documents\MAUI\Studio Sign-In 202307\Studio Sign-In 202307\bin\Debug\net7.0-maccatalyst\maccatalyst-x64\Studio Sign-In 202307.dll
1>Done building project "Studio Sign-In 202307.csproj".
1>Studio Sign-In 202307 -> E:\Documents\MAUI\Studio Sign-In 202307\Studio Sign-In 202307\bin\Debug\net7.0-windows10.0.19041.0\win10-x64\Studio Sign-In 202307.dll
1>C:\Program Files\dotnet\sdk\7.0.306\Sdks\NuGet.Build.Tasks.Pack\buildCrossTargeting\NuGet.Build.Tasks.Pack.targets(221,5): error : The package ID 'Studio Sign-In 202307' contains invalid characters. Examples of valid package IDs include 'MyPackage' and 'MyPackage.Sample'.
1>Done building project "Studio Sign-In 202307.csproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
========== Build started at 12:40 PM and took 06.325 seconds ==========
========== Package: 0 succeeded, 1 failed ===========

错误原因及修复方案

第一次报错:RuntimeIdentifier平台冲突

原因

MAUI默认是多平台项目,包含Android、iOS等目标框架,但发布Windows应用时,项目的RuntimeIdentifiers中混合了Windows和其他平台的标识,打包工具误将Windows的win10-x86识别为Android平台的ABI,导致校验失败。

修复

  1. 右键项目 → 编辑项目文件(打开.csproj)
  2. 修改<TargetFrameworks>节点,仅保留Windows目标框架:
    <TargetFrameworks>net7.0-windows10.0.19041.0</TargetFrameworks>
    
    移除net7.0-android、net7.0-ios、net7.0-maccatalyst等其他平台条目
  3. 修改<RuntimeIdentifiers>节点,仅保留Windows相关标识:
    <RuntimeIdentifiers>win10-x64;win10-x86;win10-arm64</RuntimeIdentifiers>
    
    移除所有非Windows的RuntimeIdentifier
  4. 保存项目文件,重新加载项目

第二次报错:包ID格式非法

原因

NuGet包ID不允许包含空格,项目名Studio Sign-In 202307中的空格违反了命名规则,导致打包时触发格式校验错误。

修复

  1. 右键项目 → 属性
  2. 切换到打包选项卡,找到包ID字段
  3. 将包ID中的空格替换为合法字符(如下划线、连字符,或直接删除空格),例如改为StudioSignIn202307或Studio-Sign-In-202307
  4. 保存设置后重新执行发布流程

正确的Windows部署流程

  1. 确保项目仅针对Windows平台(移除其他平台目标框架和RuntimeIdentifier)
  2. 修正包ID为合法格式(无空格、特殊字符)
  3. 右键项目 → 发布,选择旁加载分发方式
  4. 配置SHA-256证书(可使用自签名证书),设置版本号后点击创建
  5. 选择发布到本地文件夹或生成Packages,将输出文件复制到目标Windows机器
  6. 在目标机器上先安装证书,再运行应用安装程序完成部署

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.12 21:27:41