c# - 将 NuGet 包发布到 Github

标签 c# github nuget github-actions

我有一个 C# 类库项目的 Github 存储库:
https://github.com/JosepeDev/VarEnc

我通过 Visual Studio 创建了一个 NuGet 包文件并将其上传到 Nuget:
https://www.nuget.org/packages/VarEnc/

如何将此 NuGet 包链接到我的 GitHub 包?
我应该使用操作吗?

最佳答案

实现此目标的最佳方法之一 - 将 CI/CD 引入您的项目/存储库。 根据您的情况,最好选择云解决方案。

工具

有很多很酷的工具可以用于此目的:

我可以描述我正在使用的一些工具。

Github 操作

  1. 在 Github Actions 市场中,您可以找到 template以及配置示例
  2. 对此也有解决方案 How to push nuget package in GitHub actions
  3. 这很有帮助 article

AppVeyor

要配置此 CI,请执行以下步骤:

  1. AppVeyor上创建帐户,登录并将您的项目添加到 CI
  2. 在根存储库中创建 appveyor.yml 文件
  3. yml 脚本中,您需要配置 - image、build_script、version。 示例:
image: Visual Studio 2019

build_script:
  - ps: dotnet --info
  - ps: dotnet restore VarEnc.sln
  - ps: dotnet build VarEnc.sln

version: 0.0.1.{build}
  • appveyor.yml 文件中添加 deploy 部分
  • deploy:
    - provider: NuGet
      server: path to nuget org your package
      api_key:
        secure: ...
      skip_symbols: true
      on:
        branch: master
    - provider: NuGet
      name: production
      api_key:
        secure: ...
      on:
        branch: master
        appveyor_repo_tag: true
    

    有关 AppVeyor publish 的更多信息,您可以在 official documentation 中找到或有帮助article来自安德鲁·洛克

    特拉维斯 CI

    Travis CI 工具的情况相同,但 yml 文件会略有不同。

    1. AppVeyor 方法相同的步骤
    2. 在根存储库中创建 .travis.yml 文件
    3. 配置初始 yml 脚本
    language: csharp
    dist: xenial
    sudo: required
    solution: VarEnc.sln
    mono: none
    dotnet: 3.1
    
    script:
     - dotnet --version
     - dotnet restore
     - dotnet build
    
  • 在脚本中配置部署。您可以在这里找到解决方案 - How do I deploy nuget packages in Travis CI?
  • 享受在项目中配置 CI 的乐趣! github

    关于c# - 将 NuGet 包发布到 Github,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65540023/

    相关文章:

    c# - SSLStream 读取无效数据 + KB3147458 SSLStream 错误(?)

    c# - 接口(interface)实现与接口(interface)继承 - 定义

    c# - ?? system.DBNull 中的运算符

    php - 新的 GitHub Push to Master -> 压缩,发送到 S3

    git - 哪些程序使用 .gitconfig 中的 [github] 部分?

    exe - 真正是 exe 命令的 Nuget 包?

    c# - WPF 应用程序的异步和填充数据

    github - Git 文件夹到 google colab

    visual-studio-2015 - Visual Studio 无法识别已安装 NuGet 包的头文件

    c# - 为什么 PCL NuGet 包无法定位 Xamarin 平台?