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

如何在net7.0-macos项目中指定arm64架构作为目标?

可行,可通过以下几种方式切换为arm64架构

完全可以将你的.NET 7多目标应用的macos目标架构切换为arm64,适配M1芯片的Mac,具体实现方式如下:

1. 修改项目文件(持久化配置)

打开项目的.csproj文件,针对net7.0-macos目标添加架构配置:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFrameworks>net7.0-windows;net7.0-macos</TargetFrameworks>
  </PropertyGroup>

  <!-- 单独为macos目标指定arm64架构 -->
  <PropertyGroup Condition="'$(TargetFramework)' == 'net7.0-macos'">
    <RuntimeIdentifier>osx-arm64</RuntimeIdentifier>
    <!-- 若需同时支持x64和arm64,可替换为复数形式:
    <RuntimeIdentifiers>osx-x64;osx-arm64</RuntimeIdentifiers>
    -->
  </PropertyGroup>
</Project>

保存后重新构建,macos目标的输出路径会变为bin/Debug/net7.0-macos/osx-arm64。

2. 命令行构建时指定架构

无需修改项目文件,每次构建macos目标时通过命令指定架构:

dotnet build -f net7.0-macos -r osx-arm64

3. 通过IDE可视化设置(以Visual Studio for Mac为例)

  1. 右键项目 → 选择「选项」
  2. 进入「生成」→「常规」页面
  3. 在「目标运行时」下拉菜单中选择osx-arm64
  4. 保存设置后重新构建即可

额外说明

  • M1芯片运行原生arm64架构的应用无需Rosetta 2翻译,性能表现更优
  • 若设置RuntimeIdentifiers(复数),构建后会同时生成x64和arm64两个架构的输出目录

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.11 04:50:46