曦远 (DealiAxy)一份私人的文字刊物

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 分钟

讨论

共 0 条

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

加载评论中…