How can I push Nuget Package to GitHub Packages?

3.1k Views Asked by At

I'm trying to push simple .Net Core Class Library to GitHub Packages. I've read all of documentation in 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

I've created the .nupkg file but cannot push it to GitHub. How can I do that? Push command gives the following error:

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).

Here is my nuget.config in my project

<?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>

Here is .csproj file

<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

There are 1 best solutions below

0
On

For those who are still looking for a solution.

  1. Add the following line to your csrpoj file between the tags:
<RepositoryUrl>here goes your repo url</RepositoryUrl>

e.g:

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

  2. You can now run dotnet nuget push with the required arguments.