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

Mac上Xamarin Forms iOS/Android项目无法运行的报错咨询

解决Mac环境下Xamarin Forms iOS/Android构建与NuGet还原错误

问题症状

  • 构建iOS/Android项目时均触发MSB4019错误:

    /Library/Frameworks/Mono.framework/Versions/6.12.0/lib/mono/xbuild/Current/Microsoft.Common.props(3,3): Error MSB4019: The imported project "/Users/…..iOS/obj/ABSConfigurator.iOS.csproj..props" was not found. Confirm that the expression in the Import declaration “ABSConfigurator.iOS.csproj..props" is correct, and that the file exists on disk. (MSB4019)

  • NuGet包还原时提示依赖缺失:

    Error: NuGet packages need to be restored before building. NuGet MSBuild targets are missing and are needed for building. The NuGet MSBuild targets are generated when the NuGet packages are restored.

解决步骤

1. 彻底清理项目残留

  • 关闭Visual Studio for Mac
  • 进入项目根目录,删除以下内容:
    • 所有项目下的obj、bin文件夹
    • 根目录的.vs、packages文件夹
    • 项目目录中类似ABSConfigurator.iOS.csproj.nuget.g.props的自动生成文件(若存在)

2. 强制还原NuGet包

打开终端,切换到项目根目录,执行命令:

nuget restore ABSConfigurator.sln

如果nuget命令不可用,可在Visual Studio中右键点击解决方案 → 还原NuGet包。

3. 修正项目文件的导入配置

打开iOS/Android项目的.csproj文件,找到错误的导入节点:

<Import Project="obj/ABSConfigurator.iOS.csproj.*.props" />

替换为带存在性检查的明确路径:

<Import Project="obj/ABSConfigurator.iOS.csproj.nuget.g.props" Condition="Exists('obj/ABSConfigurator.iOS.csproj.nuget.g.props')" />

此修改可避免文件未生成时的导入报错。

4. 更新开发环境组件

当前使用的Mono 6.12.0版本较旧,存在兼容性隐患:

  • 打开Visual Studio for Mac → Visual Studio → 检查更新,升级至最新稳定版
  • 同步更新Mono框架,确保与Visual Studio版本匹配

5. 重新构建项目

完成上述操作后,打开解决方案,依次执行清理解决方案和重新生成解决方案。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.10 00:55:15