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

Visual Studio 2022 for Mac编译报错:aspnet_compiler.exe无效

解决Visual Studio 2022 for Mac中aspnet_compiler.exe找不到的问题

问题背景

编译目标框架为.NET 4.6.1的解决方案时,报错Library/Frameworks/Mono.framework/Versions/6.12.0/lib/mono/4.5/aspnet_compiler.exe is invalid,且在指定目录及Mono所有子文件夹中均未找到该文件。

解决方案

1. 升级Mono版本

Mono 6.12.0版本存在ASP.NET工具路径的映射问题,aspnet_compiler.exe并未放在4.5目录下:

  • 打开终端执行mono --version确认当前版本
  • 下载并安装适配VS2022 for Mac的Mono稳定新版本(如6.12.x后续补丁版或更高分支)
  • 重启VS2022 for Mac后重新编译

2. 手动定位并指定工具路径

  • 终端执行命令查找aspnet_compiler.exe实际位置:
    find /Library/Frameworks/Mono.framework -name "aspnet_compiler.exe"
    
  • 打开项目的.csproj文件,找到或添加<AspNetCompiler>节点,指定ToolPath为查到的路径,示例:
    <Target Name="MvcBuildViews" AfterTargets="AfterBuild" Condition="'$(MvcBuildViews)'=='true'">
      <AspNetCompiler VirtualPath="temp" PhysicalPath="$(WebProjectOutputDir)" ToolPath="/Library/Frameworks/Mono.framework/Versions/Current/lib/mono/xbuild-frameworks/.NETFramework/v4.6.1/lib" />
    </Target>
    

3. 清理并重置项目配置

  • 右键项目→选项→应用程序,确认目标框架为.NET Framework 4.6.1且关联正确的Mono运行时
  • 执行项目→清理命令,删除项目目录下的bin和obj文件夹,重新生成解决方案

4. 修复VS2022 for Mac组件

  • 启动Launchpad中的Visual Studio Installer,选择VS2022 for Mac点击修改
  • 确保勾选.NET Framework 4.x相关组件及ASP.NET工具集,执行修复操作

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.17 20:52:05