我有一个 C# 类库项目的 Github 存储库:
https://github.com/JosepeDev/VarEnc
我通过 Visual Studio 创建了一个 NuGet 包文件并将其上传到 Nuget:
https://www.nuget.org/packages/VarEnc/
如何将此 NuGet 包链接到我的 GitHub 包?
我应该使用操作吗?
最佳答案
实现此目标的最佳方法之一 - 将 CI/CD 引入您的项目/存储库。 根据您的情况,最好选择云解决方案。
工具
有很多很酷的工具可以用于此目的:
- AppVeyor - 云解决方案
- Travis CI - 云解决方案
- CircleCI - 云解决方案
- Jenkins - 现场
- 还有Github Actions - 云解决方案
- 以及许多其他乐器...
我可以描述我正在使用的一些工具。
Github 操作
- 在 Github Actions 市场中,您可以找到 template以及配置示例
- 对此也有解决方案 How to push nuget package in GitHub actions
- 这很有帮助 article
AppVeyor
要配置此 CI,请执行以下步骤:
- 在AppVeyor上创建帐户,登录并将您的项目添加到 CI
- 在根存储库中创建
appveyor.yml
文件 - 在
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 文件会略有不同。
- 与
AppVeyor
方法相同的步骤 - 在根存储库中创建
.travis.yml
文件 - 配置初始
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 的乐趣!
关于c# - 将 NuGet 包发布到 Github,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65540023/