zoukankan      html  css  js  c++  java
  • 2019-11-20-Github-给仓库上传-NuGet-库

    title author date CreateTime categories
    Github 给仓库上传 NuGet 库
    lindexi
    2019-11-20 08:18:14 +0800
    2019-10-19 15:55:49 +0800
    git

    在 Github 可以发布自己的 NuGet 库,本文将告诉大家如何发布

    在 Github 的仓库的首页,可以看到 Package 功能

    点击打开一个项目的 Package 默认会邀请你加入,点击开启功能

    在 Github 会显示如何做 NuGet 的上传,上面的 GH_TOKEN 就是自己生成的代表自己密码,请看文档 创建用于命令行的个人访问令牌 - GitHub 帮助

    大概的方法就是点击 Settings -> Developer settings -> Personal access tokens 如下图

    单击 Generate new token(生成新令牌)

    输入随意的名字,然后注意勾选 Package 权限,也就是 write:packagesread:packages 权限

    将页面拉到最下,点击 Generate token 按钮就可以创建密码

    如图片的 e9040b0fb3fbd0b4971660c1c04d615a630dce6e 就是我创建的密码,这个密码请保存起来,因为刷新页面就看不到了

    然后在对应的仓库配置密码,在默认打开 package 页面的时候就可以看到

     // Step 1: Authenticate
    $ nuget source Add -Name "GitHub" -Source "https://nuget.pkg.github.com/lindexi/index.json" -UserName lindexi -Password GH_TOKEN
    
    // Step 2: Pack
    $ nuget pack
    
    // Step 3: Publish
    $ nuget push "lindexi_gd.nupkg" -Source "GitHub" 

    小伙伴的第一步的 Source 的内容请替换为你自己的仓库的内容,还需要替换的是刚才 github 生成的 GH_TOKEN 密码

    如我将 GH_TOKEN 替换为上面复制的密码,对每个组织和个人创建一个 Name 所以我就将上面的 GitHub 替换为 GitHubLindexi 这样就可以设置上传

    nuget source Add -Name "GitHubLindexi" -Source "https://nuget.pkg.github.com/lindexi/index.json" -UserName lindexi -Password e9040b0fb3fbd0b4971660c1c04d615a630dce6e

    接下来创建一个测试的 NuGet 包

    dotnet new console -o Lindexi_gd

    然后编译生成 NuGet 库

    cd Lindexi_gd
    dotnet pack
    cd binDebug

    binDebug 文件夹可以看到 nupkg 文件,用下面命令上传

    nuget push Lindexi_gd.1.0.0.nupkg -Source GithubLindexi

    刷新一下页面就可以看到上传的文件

    如果在上传的时候提示下面代码

    RepoAcceptsPackageUploads: Repository "lindexi/HehuhallqaLinearjeebar.Source" does not exist.

    原因是要求 NuGet 库的 id 必须要在对应的 github 组织找到对应的仓库,如我上面上传 HehuhallqaLinearjeebar.Source.1.0.0.nupkg 文件,但是我没有 HehuhallqaLinearjeebar.Source 仓库,所以提示不能上传

    此时可以通过在 .nuspec 文件添加 repository 属性,格式如下

    <repository type="git" url="https://github.com/lindexi/HehuhallqaLinearjeebar"/>

    这样多个库可以使用相同仓库,上面代码需要写到 package 的 metadata 才能使用

    <package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
        <metadata>
          <id>HehuhallqaLinearjeebar.Source</id>
          <version>1.0.3</version>
          <authors>lindexi</authors>
          <description>Sample exists only to show a sample .nuspec file.</description>
          <language>en-US</language>
          <repository type="git" url="https://github.com/lindexi/HehuhallqaLinearjeebar"/>
        </metadata>
    </package>

    如果是在 csporj 可以通过添加下面属性

        <RepositoryType>git</RepositoryType>
        <RepositoryUrl>https://github.com/lindexi/UWP</RepositoryUrl>

    注意 RepositoryUrl 的格式是 用户名/仓库 如果自己的上传的文件是在仓库里面的文件夹,请写在 PackageProjectUrl 属性

  • 相关阅读:
    数据结构 括号法二叉树转化为二叉链表链式存储结构
    数据结构 二叉树的非递归遍历算法再回顾
    C语言算法 设计一个算法,将数组m个元素循环右移。要求算法空间复杂度为O(1)
    JAVA 递归输出所有可能的出栈序列
    C语言数据结构 头尾指针数组的综合应用
    C语言 重写strcmp函数
    C语言数据结构 判断出栈序列合法性
    PMD执行Java代码分析的原理
    Redis缓存和MySQL数据一致性方案详解
    mybtais 源码分析
  • 原文地址:https://www.cnblogs.com/lindexi/p/12086308.html
Copyright © 2011-2022 走看看