# install-dotnet-harmonyos **Repository Path**: lightsever/install-dotnet-harmonyos ## Basic Information - **Project Name**: install-dotnet-harmonyos - **Description**: 帮助鸿蒙pc 安装dotnet 环境的工具 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 3 - **Forks**: 1 - **Created**: 2026-06-15 - **Last Updated**: 2026-06-28 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # install-dotnet-harmonyos 在 **HarmonyOS PC**(鸿蒙内核 1.12+,aarch64,musl libc)上安装 .NET SDK。 ## 状态 - **CoreCLR 路径**:已完全移植跑通。throw/catch、并发 GC、信号注入、ARM64 弱内存模型等问题全部修复,能正常 build/run 托管应用。 - **NativeAOT 路径**:已跑通。`dotnet publish -r ohos-arm64 -p:PublishAot=true` 端到端可用,产出可执行 ELF。 ## 安装 ```sh ./install-dotnet-harmonyos.sh # 默认安装到 ~/.dotnet_oh ./install-dotnet-harmonyos.sh --specname ab # 装副本到 ~/.dotnet_oh_ab(用于调试) ./install-dotnet-harmonyos.sh --prefix /opt/foo # 自定义路径 ./install-dotnet-harmonyos.sh --version 10.0.301 # 指定 SDK 版本 ./install-dotnet-harmonyos.sh --skip-aot # 跳过 NativeAOT 安装 ``` 安装后会部署: - `~/bin/dotnet`(或 `~/bin/dotnet_ab`)— 全局命令 - `~/bin/sign-elf` — ELF 签名工具 - `~/bin/sign-singlefile` — 单文件产物签名工具 wrapper 拦截 `build`/`publish` 子命令,执行完后自动调 `sign-elf`/`sign-singlefile` 签产物 ELF,无需 `Directory.Build.targets`。 ## 仓库职责 本仓库**只负责安装**: - `native-libs/` — OHOS PAL 修复版 `.so`(dotnet runtime、ICU、OpenSSL、Roslyn) - `nativeaot/` — NativeAOT 文件(ILC managed dll、静态库、corelib、shim objects、apply-overlay.sh) - `install-dotnet-harmonyos.sh` — 安装脚本 所有源码 build 在 **oh_dotnet 仓库**完成,产物复制到本仓库。本仓库不依赖 oh_dotnet 仓库。 ## NativeAOT `dotnet publish -r ohos-arm64 -p:PublishAot=true` 直接产出可执行 ELF: ```sh cd your/project dotnet publish -r ohos-arm64 -p:PublishAot=true -c Release ./bin/Release/net10.0/ohos-arm64/publish/your_app # 直接运行,无需 LD_LIBRARY_PATH ``` wrapper 在 `publish` 子命令时会自动调用 `${DOTNET_ROOT}/nativeaot/apply-overlay.sh`: - 用我们的 managed `ilc.dll` 替换 NuGet 包里的 native ilc(OHOS 跑不了 musl native ELF) - 给 NuGet 包里的 `.so` 加 OHOS codesign - 在 `nativeaot.linux-musl-arm64/runtimes/` 下建 `ohos-arm64/` 子目录,让 MSBuild 默认 glob 命中 manifest 增量:`${DOTNET_ROOT}/.ilc-overlay.manifest` 记录文件 size+mtime,命中跳过。 ## 卸载 ```sh ./install-dotnet-harmonyos.sh --uninstall ./install-dotnet-harmonyos.sh --specname ab --uninstall # 卸载副本 ``` 清理 SDK 目录、wrapper、`~/bin/sign-elf`、`~/bin/sign-singlefile`。 ## 使用 ```sh dotnet new console dotnet build # 自动签 apphost,无需手动签名 dotnet run --no-build dotnet publish -p:PublishSingleFile=true --self-contained false # 自动签单文件产物 ``` `dotnet build` 和 `dotnet publish` 出来的 ELF 可以直接执行——wrapper 拦截 `build`/`publish` 子命令后自动签名。csproj 需显式指定 `ohos-arm64`(或 `-r ohos-arm64`)。 手动签名: ```sh sign-elf # 自动签当前项目 bin/ 下所有 ELF sign-elf ./bin/Debug/net10.0/app sign-singlefile ./publish/app # 签单文件产物(拆分 ELF + bundle → 签 → 拼接) ``` ## 文档 - [`dotnet-on-harmonyos.md`](dotnet-on-harmonyos.md) — 背景原理、PAL bug 表、命令参数、依赖、安装流程、已知限制 - [`ld-preload-shims.md`](ld-preload-shims.md) — LD_PRELOAD shim 实现说明