.net - 如何将 Nuget 包推送到 GitHub 包?

标签 .net github nuget nuget-package github-package-registry

我正在尝试将简单的 .Net Core 类库推送到 GitHub Packages。我已阅读 https://docs.github.com/en/free-pro-team@latest/packages/using-github-packages-with-your-projects-ecosystem/configuring-dotnet-cli-for-use-with-github-packages 中的所有文档

我已经创建了 .nupkg 文件,但无法将其推送到 GitHub。我怎样才能做到这一点?推送命令给出以下错误:

dotnet nuget push "bin/Release/Vegas.Util.AppLogger.1.0.0.nupkg" --source "github"

PUT https://nuget.pkg.github.com/kenannur/
warn : No destination repository detected. Ensure the source project has a 'RepositoryUrl' property defined. If you're using a nuspec file, ensure that it has a repository element with the required 'type' and 'url' attributes.
  BadRequest https://nuget.pkg.github.com/kenannur/ 155 ms
error: Response status code does not indicate success: 400 (Bad Request).

这是我项目中的 nuget.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <packageSources>
        <clear />
        <add key="github" value="https://nuget.pkg.github.com/kenannur/index.json" />
    </packageSources>
    <packageSourceCredentials>
        <github>
            <add key="Username" value="kenannur" />
            <add key="ClearTextPassword" value="*********************" />
        </github>
    </packageSourceCredentials>
</configuration>

这是.csproj文件

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net5.0</TargetFramework>
    <PackageId>Vegas.Util.AppLogger</PackageId>
    <Authors>Kenan Nur</Authors>
    <Owners>kenannur</Owners>
    <PackageTags>log logger</PackageTags>
    <Title>AppLogger</Title>
    <Description>Basit console logger</Description>
    <PackageVersion>1.0.0</PackageVersion>
    <Version>1.0.0</Version>
    <RepositoryUrl>https://github.com/kenannur/applogger</RepositoryUrl>
    <RepositoryType>git</RepositoryType>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="NuGet.Build.Packaging" Version="0.2.5-dev.8">
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
      <PrivateAssets>all</PrivateAssets>
    </PackageReference>
  </ItemGroup>
</Project>

最佳答案

对于那些仍在寻找解决方案的人。

  1. 将以下行添加到您的 csrpoj 文件中的标记之间:
<RepositoryUrl>here goes your repo url</RepositoryUrl>

例如:

<PropertyGroup>
    ...
    <RepositoryUrl>https://github.com/johndoe/hello-world.git</RepositoryUrl>
</PropertyGroup>
  1. dotnet pack --configuration Release

  2. 您现在可以使用所需参数运行 dotnet nuget push

关于.net - 如何将 Nuget 包推送到 GitHub 包?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65182182/

相关文章:

git - ! [rejected] master -> master(先获取)

asp.net - 如何安装 ServiceStack.Interfaces?

macos - OSX 上的 SourceTree : Clicking "Always Allow" bitbucket to use my password keychain has no effect

.net - 如何将一个巨大的解决方案分成更小的部分

msbuild - 在 msbuild 中检索 nupkg 版本号

c# - 在 WinForms 选项卡控件中,我如何知道您正在从/向哪个选项卡移动?

.net - MSDN 中的 asp :FileUpload. FileBytes 示例令人困惑

.net - 使用命令行发布 WCF 服务(或 ASP.NET Web 应用程序)

.net - 如何使用 C# 正则表达式匹配任意字符串中的最后一个字符?

git - 跨平台项目的最佳 Git 策略