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

使用dotnet new api -aot报错:'-aot'不是有效选项的咨询

解决办法
  • 使用正确的项目创建命令
    在.NET 8 Preview 4中,创建支持Native AOT的API项目需使用--native-aot参数,替代旧的-aot,执行命令:

    dotnet new api --native-aot
    
  • 手动为现有项目启用AOT
    若已创建普通API项目,可编辑项目文件(.csproj),在<PropertyGroup>节点内添加AOT配置:

    <PublishAot>true</PublishAot>
    

    完成后执行发布命令生成AOT编译产物:

    dotnet publish -c Release
    
  • 升级Visual Studio版本
    你当前使用的Visual Studio 17.0 Preview 1版本与.NET 8 Preview 4兼容性较差,建议升级至Visual Studio 17.7 Preview及以上版本,确保工具链与SDK版本匹配。

内容的提问来源于stack exchange,提问作者Imran Qadir Baksh - Baloch

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.19 13:49:56