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
相关产品推荐
相关产品推荐

