Push nuget package from difference owner

Is there a way to push a nuget project without <RepositoryUrl> or from a difference owner to GitHub package?

In our case, we have one github account where some old repos are stored and the new repos are stored under a organization owned by that github account.

e.g.
GitHub account: /companyGitHub
GitHub organization: /companyName
Under .csproj: <RepositoryUrl>https://github.com/companyGitHub/nuget-project</RepositoryUrl>

When I run

nuget push nuget-project.1.2.1.nupkg -Source "companyName's github package" -SkipDuplicate

After it is completed

Pushing nuget-project.1.2.1.nupkg to 'https://nuget.pkg.github.com/companyName'...
  PUT https://nuget.pkg.github.com/companyName/
  OK https://nuget.pkg.github.com/companyName/ 3342ms
Your package was pushed.

It is pushed to companyGitHub’s github package instead of pushing the package to companyName that tagged with Published x days ago by companyGitHub in companyGitHub/nuget-project.


I tried removing <RepositoryUrl>, and it won’t work

Pushing nuget-project.1.2.1.nupkg to 'https://nuget.pkg.github.com/companyName'...
  PUT https://nuget.pkg.github.com/companyName/
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/companyName/ 1675ms
Response status code does not indicate success: 400 (Bad Request).

Change to <RepositoryUrl>https://github.com/companyName/</RepositoryUrl> will not work

Pushing nuget-project.1.2.1.nupkg to 'https://nuget.pkg.github.com/companyName'...
  PUT https://nuget.pkg.github.com/companyName/
WARNING: repo name with owner has wrong number of components: [companyName] (wanted 2, got 1)
  BadRequest https://nuget.pkg.github.com/companyName/ 2330ms
Response status code does not indicate success: 400 (Bad Request).

Change to <RepositoryUrl>https://github.com/companyName/fakeRepo</RepositoryUrl> will not work

Pushing nuget-project.1.2.1.nupkg to 'https://nuget.pkg.github.com/companyName'...
  PUT https://nuget.pkg.github.com/companyName/
  NotFound https://nuget.pkg.github.com/companyName/ 2523ms
Response status code does not indicate success: 404 (Not Found).

Change to <RepositoryUrl>https://github.com/companyName/anotherRepo</RepositoryUrl> will work

Pushing nuget-project.1.2.1.nupkg to 'https://nuget.pkg.github.com/companyName'...
  PUT https://nuget.pkg.github.com/companyName/
  OK https://nuget.pkg.github.com/companyName/ 3716ms
Your package was pushed.

BUT, the package will be marked with an incorrect info since the actual RepositoryUrl is https://github.com/companyGitHub/nuget-project instead of https://github.com/companyName/anotherRepo in the Github package of companyName

Hi @jasonycw,

The <RepositoryUrl> must always point to a repository that the token (PAT) doing the publish has write access to. This is the only way to tell GitHub Packages which repository the package is associated with.

If you would prefer to leave the <RepositoryUrl> in your project as https://github.com/companyGitHub/nuget-project, you can change the repository URL as part of the publishing process like this:

dotnet tool install gpr -g
gpr push path/to/*.nupkg --repository https://github.com/companyName/anotherRepo -k <PAT>

This way the repository URL will only be changed when the package is published to GitHub. You can leave the real repository URL when publishing to nuget.org.

I hope that helps!

Regards,
Jamie.

Thanks @jcansdale for the quick reply.

I know I can use gpr push to push to with a difference RepositoryUrl however, that’s not what I want.

The <RepositoryUrl> must always point to a repository that the token (PAT) doing the publish has write access to.

In my example, since companyGitHub is the owner of companyName, I was expecting I can push package from owner repo to organization’s github package with the link back to the owner’s repo URL.
Since companyGitHub definitely has write access to companyName and I am using a personal access token from companyGitHub to push to companyName.

My goal is to have the package in companyName and tagged " Published x days ago by companyGitHub in companyGitHub/nuget-project"

If I force --repository https://github.com/companyName/anotherRepo than under companyName’s package page, the package is pointed to a wrong repository and the anotherRepo will have a link to a package that is not responsible by it.

I’m afraid this isn’t possible at the moment. The package and the repository can have different names, but they must have the same owner (org or user).

In a future version, packages won’t need to be linked to a repository like this. What you could do for the moment is create a repository called companyName/packages, that can be associated with packages from all your repositories.

Does that make sense?

Yes, I can create that temporary repo just to make the package push work but this workaround is far from ideal.

In a future version, packages won’t need to be linked to a repository like this.

Hope this feature come asap. :slight_smile:

The lifetime of packages is associated with their repo. This will need to be a permanent, not temporary home for your packages.

Hope this feature come asap. :slight_smile:

I hope so to! :crossed_fingers: