GitHub packages registry can be use to keep your organization NuGet packages privately or share them publicly. If you create a package in a private repo it would be private to the repo or for the organization if you use an organization. If you keep your packages in a public repo you can share it publicly. Ideally when you build reusable NuGet packages you would build and publish such packages with GitHub action workflow to your GitHub packages. While implementing this you may encounter “Response status code does not indicate success: 400 (Bad Request)” at the push of the package, due to special needs of GitHub based NuGet packages. Let’s look at them in this post.
You can build your NuGet package with dotnet pack command or using nuget pack command. Regardless of your package mechanism you might encounter below mentioned warning and the Bad Request error when you try to push the created NuGet package to the GitHub packages.
Pushing NuGetPackageDemo.1.0.0-417492834.nupkg to 'https://nuget.pkg.github.com/ChDemoOrg'...
PUT https://nuget.pkg.github.com/ChDemoOrg/
WARNING: 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/ChDemoOrg/ 244ms
Response status code does not indicate success: 400 (Bad Request).
Error: Process completed with exit code 1.
Generally, when use dotnet pack you have to set couple of settings in your project file for example look at below csproj.
Even though above settings let you create the NuGet package using dotnet pack command successfully and you can push to registries such as nuget.org or Azure DevOps artifact feeds, once you try to push such package to GitHub packages via GitHub actions or manually you will see below warning with bad request as error.
WARNING: 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.
When you are using a nuspec file (see example below) and using nuget pack command following is sufficient for you to create and push the package to other registries. However, same bad request and warning is resulted with GitHub packages.
As the warning demags you must specify the url for the repo in your csproj if you use the dotnet pack command to create the NuGet package targeting GitHub packages. Cs proj should contain the package url like below.
<RepositoryUrl>https://github.com/yourgithubaccountororgname/reponame.git</RepositoryUrl>
If you are using a nuspec it must specify the url and the type as git. Specifying type as git in nuspec is must and if you only specify the repo url you would still get the same error and warning.
<repository type="git" url="https:// github.com/yourgithubaccountororgname/reponame.git "></repository>
Once you package the NuGet package with the repository url as mentioned above in csproj or repository url and type in nuspec, the package you create would be able to push to GitHub packages.
No comments:
Post a Comment