首页 > 解决方案 > 在 GitHub 上自动发布 .Net Core 应用程序

问题描述

我不想在 GitHub Repos 中制作 .Net Core 应用程序,它会自动构建并将构建的二进制文件推送到新版本,但我不知道要在 GitHub 上进行设置。因此,例如,我有我的 .Net Core 控制台应用程序并将我的分支与更改拉到 master 中。现在构建应该在构建之后开始(这就是我所拥有的)二进制文件应该被压缩并附加到一个新的版本,所以会有连续的新版本。

希望有人理解并可以提供帮助。

这是我到目前为止的工作流程

name: .NET Core

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:
  build:

    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v2
    - name: Setup .NET Core
      uses: actions/setup-dotnet@v1
      with:
        dotnet-version: 3.1.201
    - name: Install dependencies
      run: dotnet restore
    - name: Build
      run: dotnet build --configuration Release --no-restore

标签: github.net-coredevopsgithub-actions

解决方案


感谢 Deepak Mishra,我现在已经解决了这个问题

name: .NET Core

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:
  build:

    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v2
    - name: Setup .NET Core
      uses: actions/setup-dotnet@v1
      with:
        dotnet-version: 3.1.101
    - name: Install dependencies
      run: dotnet restore
    - name: Build
      run: dotnet build --configuration Release --no-restore
    - name: Zip the Build
      run: zip -r ${{ secrets.ReleaseZipName }} ./AppName/bin/Release/netcoreapp3.1/ 
    - name: Create Release
      id: create_release
      uses: actions/create-release@v1
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      with:
        tag_name: ${{ github.run_number }}
        release_name: Release ${{ github.ref }}
        body: New Release.
        draft: false
        prerelease: false
    - name: Upload Release Asset
      uses: actions/upload-release-asset@v1
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      with:
        upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps 
        asset_path: ./${{ secrets.ReleaseZipName }}.zip
        asset_name: ${{ secrets.ReleaseZipName }}.zip
        asset_content_type: application/zip

推荐阅读