前言 🔗
一直很好奇那些在github中非常好的项目是怎么来发布Release的,恰巧最近有空
当然github actions的功能非常多,我也是刚入门的小白,本篇文件仅介绍如何使用actions来实现.net8 cli aot发布后直接publish到Release中
我就想在OpenWrt中非Docker运行.net aot程序就那么难吗!淦
实操 🔗
在github中创建一个存储库,然后同步拉取推送
在项目根目录中创建文件夹 .github/workflows,然后新建一个任意的yaml文件,如下所示
框架依赖时不能带入-p:PublishReadyToRun=true参数,否则会无法执行!
1name: Release Compilation
2
3on:
4 push:
5 tags:
6 - 'v*'
7
8jobs:
9 build:
10 runs-on: ${{ matrix.os }}
11 strategy:
12 matrix:
13 include:
14 - os: ubuntu-latest
15 runtime: linux-x64
16 - os: macos-latest
17 runtime: osx-x64
18 - os: windows-latest
19 runtime: win-x64
20 - os: windows-latest
21 runtime: win-arm64
22 - os: macos-latest
23 runtime: osx-arm64
24
25 steps:
26 - name: Checkout code
27 uses: actions/checkout@v3
28
29 - name: Setup .NET
30 uses: actions/setup-dotnet@v3
31 with:
32 dotnet-version: '8.x'
33
34 - name: Build AOT
35 run: |
36 dotnet publish -c Release -r ${{ matrix.runtime }} -p:PublishAot=true -o out/aot/${{ matrix.runtime }}
37 timeout-minutes: 10
38 env:
39 DOTNET_CLI_TELEMETRY_OPTOUT: 1
40
41 - name: Build Self-contained
42 run: |
43 dotnet publish -c Release -r ${{ matrix.runtime }} -p:PublishSingleFile=true -p:SelfContained=true -p:PublishReadyToRun=true -o out/self-contained/${{ matrix.runtime }}
44 timeout-minutes: 10
45 env:
46 DOTNET_CLI_TELEMETRY_OPTOUT: 1
47
48 - name: Build Framework-dependent
49 run: |
50 dotnet --version
51 dotnet publish -c Release -r ${{ matrix.runtime }} -p:PublishSingleFile=true -p:SelfContained=false -o out/framework-dependent/${{ matrix.runtime }}
52 timeout-minutes: 10
53
54 - name: Zip the build output
55 run: |
56 if ("${{ runner.os }}" -eq "Windows") {
57 Compress-Archive -Path "out/aot/${{ matrix.runtime }}/*" -DestinationPath "out/aot-${{ matrix.runtime }}.zip"
58 Compress-Archive -Path "out/self-contained/${{ matrix.runtime }}/*" -DestinationPath "out/selfcontained-${{ matrix.runtime }}.zip"
59 Compress-Archive -Path "out/framework-dependent/${{ matrix.runtime }}/*" -DestinationPath "out/framework-${{ matrix.runtime }}.zip"
60 } else {
61 zip -r "out/aot-${{ matrix.runtime }}.zip" "out/aot/${{ matrix.runtime }}"
62 zip -r "out/selfcontained-${{ matrix.runtime }}.zip" "out/self-contained/${{ matrix.runtime }}"
63 zip -r "out/framework-${{ matrix.runtime }}.zip" "out/framework-dependent/${{ matrix.runtime }}"
64 }
65 timeout-minutes: 5
66 shell: pwsh
67
68 - name: Upload
69 uses: softprops/action-gh-release@v2
70 env:
71 GITHUB_TOKEN: ${{ secrets.MY_TOKEN }}
72 with:
73 files: |
74 out/*.zip
现在,已经配置可以将各个系统自动编译并发布二进制到Release中,分别为3种类型:aot/自包含/clr依赖
等等,到目前这一步还不足让其自动编译,请注意上述yaml文件中的on,必须符合指定的tag格式v*才可以
打开cmd输入如下指令
1# 打开当前目录
2cd xx
3
4# 创建tag
5git tag -a v1.0.0 -m "Release Version 1.0.0"
6
7# 推送tag
8git push origin v1.0.0
至此,已成艺术
当然这只是最原始的aot方法,如果非aot编译则可以对全平台支持,以下为.net 8可编译的目标平台
- win-x86
- win-x64
- win-arm
- win-arm64
- osx-x64
- osx-arm64
- linux-x64
- linux-arm
- linux-arm64
不考虑32bit,都2024年了谁还用32bit系统???
Armの硬伤 🔗
arm的aot暂时没法进行,因为.net目前不支持跨平台的交互编译(.net8)
并且.net开发团队对此进行了回复
Since there’s no standardized way to obtain native macOS SDK for use on Windows/Linux, or Windows SDK for use on Linux/macOS, or a Linux SDK for use on Windows/macOS, Native AOT does not support cross-OS compilation. Cross-OS compilation with Native AOT requires some form of emulation, like a virtual machine or Windows WSL.
结合上述回复,可以确定的是在可预见的未来.net应该不会支持跨平台编译了,请选择rust或go
并且github的actions运行时系统也并没有arm系统(不得不说还得是巨硬啊,这配置真豪华
以上种种,导致我暂时放弃了对arm原生aot的构建,在openwrt中还是用docker跑吧…