Developing Modern .NET Core Console Programs: (3) Publishing NuGet Packages to GitHub Packages
Publishing NuGet packages to GitHub Packages? Just repetitive work configuring tokens and nuget.config. Manually linking packages to repositories? GitHub's design is truly quirky. Got it done, but who has time to deal with all that.
目录6 个章节
Preface
The previous article has already published the project template's NuGet package to the official NuGet source. However, it can also be published to other sources, such as GitHub. This article documents the process of publishing to GitHub Packages.
Note: This article is based on the second article in this series. For a better understanding of the operation process, please first familiarize yourself with the code structure of this project.
Creating a GitHub token
Visit the page https://github.com/settings/tokens
Generate a classic token
Remember to check the permissions related to packages (packages)
Add nuget source configuration to the project
Create a new nuget.config file in the src/Templates directory
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<clear />
<add key="github" value="https://nuget.pkg.github.com/NAMESPACE/index.json" />
</packageSources>
<packageSourceCredentials>
<github>
<add key="Username" value="USERNAME" />
<add key="ClearTextPassword" value="TOKEN" />
</github>
</packageSourceCredentials>
</configuration>
The above is just the configuration template provided by GitHub, with a few places that need to be modified:
- Replace
USERNAMEwith the name of your personal account on GitHub. - Replace
TOKENwith a personal access token (classic). - Replace
NAMESPACEwith the name of the personal account or organization used for package scoping (包限定范围).
Publish Package
Execute dotnet pack to generate a NuGet package
Then run the following command to publish the generated NuGet package to GitHub Packages
dotnet nuget push ".\bin\Release\FluentConsole.Templates.1.1.0.nupkg" --api-key TOKEN --source github
TOKENis the one you applied for earlier.
If everything goes well, you should see the following output:
Pushing FluentConsole.Templates.1.1.0.nupkg to 'https://nuget.pkg.github.com/Deali-Axy'...
PUT https://nuget.pkg.github.com/Deali-Axy/
OK https://nuget.pkg.github.com/Deali-Axy/ 1129 毫秒
Your package was pushed.
At this point, it's done. You can visit https://github.com/Deali-Axy?tab=packages to see the published packages.
Associating the Published Package with the Code Repository
Because the project address is https://github.com/Deali-Axy/fluent-dotnet-console
and the package name is FluentConsole.Templates
these two are inconsistent, so they will not be automatically associated. We need to perform the manual association.
Go to the package details page: https://github.com/users/Deali-Axy/packages/nuget/package/FluentConsole.Templates
Click the Connect Repository button below, and select the fluent-dotnet-console project.
After binding, the repository's README can be seen on the package's main page.
In the bottom right corner of the repository, you can also see this package.
PS: GitHub is becoming more and more user-friendly.
References
_EOF_
Developing Modern .NET Core Console Programs: (3) Publishing NuGet Packages to GitHub Packages
- 本文作者:
- 程序设计实验室
- 版权声明:
- 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
相关文章
分析C#项目的单元测试覆盖率,提高代码质量
C#覆盖率分析?不就是用工具生成报告吗?VSCode、VS、Rider哪个不能干?真当这是啥高科技?
2025-08-06 · C# · 约 1 分钟
C# 扩展方法只会写 this 吗?C# 14 新语法直接把扩展方法玩出了花
.NET 10 的扩展方法语法糖?哦,用 `extension` 块定义扩展,支持属性和方法了,以前不行,现在行,真稀奇。静态扩展成员?太晚了点,给 `DateTime` 添加静态方法,终于能优雅了。升级吧,不然怎么享受这些新玩具?
2026-03-05 · C# · 约 1 分钟
C#高性能数组拷贝实验
前言 昨天 wc(Wyu_Cnk) 提了个问题 C# 里多维数组拷贝有没有什么比较优雅的写法? 这不是问对人了吗?正好我最近在搞图像处理,要和内存打交道,我一下就想到了在C#里面直接像C/C++一样做内存拷贝。 优雅?no,要的就是装逼,而且性能还要强🕶 概念 首先澄清一下 C# 里的多维数组 (Multi-dimensional Array) 是这样的 byte[,] arr = new by
2023-01-30 · C# · 约 1 分钟
在.NetCore(C#)中使用ODP-NET-Core+Dapper操作Oracle数据库
前言 虽然一直在说“去IOE化”,但是在国企和政府,Oracle的历史包袱实在太重了,甚至很多业务逻辑都是写在Oracle的各种存储过程里面实现的…… 我们的系统主要的技术栈是Django / Spring / AspNetCore,Java的不必说对Oracle支持肯定没问题,关键在于Django对Oracle版本有要求,兼容性不是特别好,Oracle版本没办法随意升级的,所以我想到用.Net
2021-12-18 · C# · 约 1 分钟
讨论
共 0 条加载评论中…