Publish NuGet to releases #815
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Publish NuGet to Releases | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| version: | |
| description: '发布版本号 (例如: 3.7.0)' | |
| required: true | |
| type: string | |
| jobs: | |
| build-and-publish: | |
| runs-on: windows-latest | |
| steps: | |
| - name: 检出代码 | |
| uses: actions/checkout@v4 | |
| - name: 安装.NET SDK | |
| uses: actions/setup-dotnet@v4 | |
| with: | |
| dotnet-version: '9.0.x' # 与现有CI配置保持一致 | |
| - name: 恢复依赖 | |
| run: dotnet restore ./src/c#/GeneralUpdate.sln # 使用解决方案统一恢复 | |
| - name: 构建项目(确保生成DLL) | |
| run: dotnet build ./src/c#/GeneralUpdate.sln -c Release --no-restore # 显式构建,避免重复恢复 | |
| - name: 打包NuGet包 | |
| run: | | |
| $projects = @( | |
| "GeneralUpdate.Bowl", | |
| "GeneralUpdate.ClientCore", | |
| "GeneralUpdate.Common", | |
| "GeneralUpdate.Core", | |
| "GeneralUpdate.Differential" | |
| ) | |
| foreach ($project in $projects) { | |
| dotnet pack ./src/c#/$project/$project.csproj ` | |
| -c Release ` | |
| -o ./nupkgs ` | |
| -p:Version=${{ github.event.inputs.version }} ` | |
| -p:PackageVersion=${{ github.event.inputs.version }} ` | |
| --no-build # 避免重复构建,使用已生成的文件 | |
| } | |
| shell: pwsh | |
| - name: 创建GitHub Release并上传NuGet包 | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: v${{ github.event.inputs.version }} | |
| name: Release v${{ github.event.inputs.version }} | |
| files: ./nupkgs/*.nupkg | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |