C# 怎么同时交叉编译 windows Linux mac ?跟 go 一样

2024 年 8 月 14 日
 yuaotian

好奇,怎么同时编译三个系统的执行文件? go 就可以,C#在发布里面没找到,搜索引擎资料也很少,跟着编译也不行。

开发:vs2022 、Rider

6187 次点击
所在节点    C#
10 条回复
fgwmlhdkkkw
2024 年 8 月 14 日
supemaomao
2024 年 8 月 14 日
如果直接用 vs 编译的话我没试过,但是我用 vs 开发,编译为 docker 镜像,是可以交叉编译为 amd 和 arm 的。理论上在 vs 中也是可以的。
sagaxu
2024 年 8 月 14 日
dotnet publish -c release -r win-x64
dotnet publish -c release -r linux-x64
dotnet publish -c release -r osx-x64
Al0rid4l
2024 年 8 月 14 日
@fgwmlhdkkkw 这是 AOT, 但是 LZ 问的也不是 AOT 啊...
liuliuliuliu
2024 年 8 月 14 日
liuliuliuliu
2024 年 8 月 14 日
如果说是“同时”
那么你需要在 csproj 中写明平台,例如
<RuntimeIdentifiers>win-x64;osx-x64;linux-x64</RuntimeIdentifiers>
然后只需要 dotnet publish 就可以了
参见
https://learn.microsoft.com/en-us/dotnet/core/project-sdk/msbuild-props#runtimeidentifier
lisxour
2024 年 8 月 15 日
native 不太清楚,但是你完全可以用.net core
LLaMA2
2024 年 8 月 15 日
yuaotian
2024 年 8 月 17 日
好的,感谢大家~~~
CodeCodeStudy
2024 年 9 月 26 日
简单来说,AOT 是不能交叉编译的,非 AOT 的话如果把 runtime 打包进去也是不能交叉编译的

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/1065009

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX