返回文章列表文章索引阅读全文
STARBLOG / 阅读手记
C#

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.

曦远 (DealiAxy)约 8 分钟
目录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 USERNAME with the name of your personal account on GitHub.
  • Replace TOKEN with a personal access token (classic).
  • Replace NAMESPACE with 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
  • TOKEN is 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 许可协议。转载请注明出处!

相关文章

在.NetCore(C#)中使用ODP-NET-Core+Dapper操作Oracle数据库

前言 虽然一直在说“去IOE化”,但是在国企和政府,Oracle的历史包袱实在太重了,甚至很多业务逻辑都是写在Oracle的各种存储过程里面实现的…… 我们的系统主要的技术栈是Django / Spring / AspNetCore,Java的不必说对Oracle支持肯定没问题,关键在于Django对Oracle版本有要求,兼容性不是特别好,Oracle版本没办法随意升级的,所以我想到用.Net

2021-12-18 · C# · 约 1 分钟

C#实现生成Markdown文档目录树

前言 之前我写了一篇关于C#处理Markdown文档的文章:C#解析Markdown文档,实现替换图片链接操作 算是第一次尝试使用C#处理Markdown文档,然后最近又把博客网站的前台改了一下,目前文章渲染使用Editor.md组件在前端渲染,但这个插件生成的目录树很丑,我魔改了一下换成bootstrap5-treeview组件,好看多了。详见这篇文章:魔改editormd组件,优化ToC渲染效

2022-10-26 · C# · 约 1 分钟

System.Text.Json使用中的几个常见问题

前言 以前.NetCore是不内置JSON库的,所以大家都用Newtonsoft的JSON库,而且也确实挺好用的,不过既然官方出了标准库,那更方便更值得我们多用用,至少不用每次都nuget安装Newtonsoft.Json库了。 不过日常开发使用中会有一些问题,本文记录一下解决方法,欢迎交流~ ~~(文章末尾包含小彩蛋)~~ 字符编码问题 默认的 System.Text.Json 序列化的时候会把

2022-05-27 · C# · 约 1 分钟

讨论

共 0 条

良言一句三冬暖,恶语伤人六月寒。

加载评论中…