Observação: GitHub Package Registry está atualmente em beta para GitHub Enterprise Server 2.22. Para participar da versão beta de sua instância do GitHub Enterprise Server, use o formulário de inscrição.
Nota: Este tipo de pacote pode não estar disponível para sua instância, porque os administradores do site podem habilitar ou desabilitar cada tipo de pacote compatível. Para obter mais informações, consulte "Configurar pacotes de suporte para a sua empresa".
Authenticating to GitHub Package Registry
Você precisa de um token de acesso para publicar, instalar e excluir pacotes no GitHub Package Registry.
Você pode usar um token de acesso pessoal (PAT) para efetuar a autenticação em GitHub Package Registry ou na API de GitHub Ao criar um token de acesso pessoal, você pode atribuir diferentes escopos de token, dependendo da sua necessidade. Para obter mais informações sobre os escopos dos pacotes para um PAT, consulte "Sobre permissões para o GitHub Packages."
Para efetuar a autenticação em um registro do GitHub Package Registry dentro de um fluxo de trabalho de GitHub Actions, você pode utilizar:
GITHUB_TOKEN
para publicar pacotes associados ao repositório do fluxo de trabalho.- um PAT para instalar pacotes associados a outros repositórios privados (que o
GITHUB_TOKEN
não consegue acessar).
Authenticating with GITHUB_TOKEN
in GitHub Actions
Use the following command to authenticate to GitHub Package Registry in a GitHub Actions workflow using the GITHUB_TOKEN
instead of hardcoding a token in a nuget.config file in the repository:
dotnet nuget add source --username USERNAME --password ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text --name github "https://nuget.HOSTNAME/OWNER/index.json"
Para obter mais informações sobre GITHUB_TOKEN
usado nos fluxos de trabalho de GitHub Actions, consulteAutenticação em um fluxo de trabalho".
Authenticating with a personal access token
Você deve usar um token de acesso pessoal com os escopos apropriados para publicar e instalar pacotes no GitHub Package Registry. Para obter mais informações, consulte "Sobre GitHub Package Registry."
To authenticate to GitHub Package Registry with the dotnet
command-line interface (CLI), create a nuget.config file in your project directory specifying GitHub Package Registry as a source under packageSources
for the dotnet
CLI client.
You must replace:
USERNAME
with the name of your user account on GitHub.TOKEN
with your personal access token.OWNER
with the name of the user or organization account that owns the repository containing your project.HOSTNAME
with the host name for sua instância do GitHub Enterprise Server.
If your instance has subdomain isolation enabled:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<clear />
<add key="github" value="https://nuget.HOSTNAME/OWNER/index.json" />
</packageSources>
<packageSourceCredentials>
<github>
<add key="Username" value="USERNAME" />
<add key="ClearTextPassword" value="TOKEN" />
</github>
</packageSourceCredentials>
</configuration>
If your instance has subdomain isolation disabled:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<clear />
<add key="github" value="https://HOSTNAME/_registry/nuget/OWNER/index.json" />
</packageSources>
<packageSourceCredentials>
<github>
<add key="Username" value="USERNAME" />
<add key="ClearTextPassword" value="TOKEN" />
</github>
</packageSourceCredentials>
</configuration>
Publishing a package
You can publish a package to GitHub Package Registry by authenticating with a nuget.config file.
Publishing a package using a nuget.config file
When publishing, you need to use the same value for OWNER
in your csproj file that you use in your nuget.config authentication file. Specify or increment the version number in your .csproj file, then use the dotnet pack
command to create a .nuspec file for that version. For more information on creating your package, see "Create and publish a package" in the Microsoft documentation.
-
Autenticar para GitHub Package Registry. Para obter mais informações, consulte "Authenticating to GitHub Package Registry."
-
Create a new project.
dotnet new console --name OctocatApp
-
Add your project's specific information to your project's file, which ends in .csproj. You must replace:
OWNER
with the name of the user or organization account that owns the repository containing your project.REPOSITORY
with the name of the repository containing the package you want to publish.1.0.0
with the version number of the package.HOSTNAME
with the host name for sua instância do GitHub Enterprise Server.
<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>netcoreapp3.0</TargetFramework> <PackageId>OctocatApp</PackageId> <Version>1.0.0</Version> <Authors>Octocat</Authors> <Company>GitHub</Company> <PackageDescription>This package adds an Octocat!</PackageDescription> <RepositoryUrl>https://HOSTNAME/OWNER/REPOSITORY</RepositoryUrl> </PropertyGroup> </Project>
-
Package the project.
dotnet pack --configuration Release
-
Publish the package using the
key
you specified in the nuget.config file.dotnet nuget push "bin/Release/OctocatApp.1.0.0.nupkg" --source "github"
Após publicar um pacote, você poderá visualizá-lo no GitHub. Para obter mais informações, consulte "Visualizar pacotes".
Publishing multiple packages to the same repository
To publish multiple packages to the same repository, you can include the same GitHub repository URL in the RepositoryURL
fields in all .csproj project files. GitHub matches the repository based on that field.
For example, the OctodogApp and OctocatApp projects will publish to the same repository:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.0</TargetFramework>
<PackageId>OctodogApp</PackageId>
<Version>1.0.0</Version>
<Authors>Octodog</Authors>
<Company>GitHub</Company>
<PackageDescription>This package adds an Octodog!</PackageDescription>
<RepositoryUrl>https://HOSTNAME/octo-org/octo-cats-and-dogs</RepositoryUrl>
</PropertyGroup>
</Project>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.0</TargetFramework>
<PackageId>OctocatApp</PackageId>
<Version>1.0.0</Version>
<Authors>Octocat</Authors>
<Company>GitHub</Company>
<PackageDescription>This package adds an Octocat!</PackageDescription>
<RepositoryUrl>https://HOSTNAME/octo-org/octo-cats-and-dogs</RepositoryUrl>
</PropertyGroup>
</Project>
Installing a package
Using packages from GitHub in your project is similar to using packages from nuget.org. Add your package dependencies to your .csproj file, specifying the package name and version. For more information on using a .csproj file in your project, see "Working with NuGet packages" in the Microsoft documentation.
-
Autenticar para GitHub Package Registry. Para obter mais informações, consulte "Authenticating to GitHub Package Registry."
-
To use a package, add
ItemGroup
and configure thePackageReference
field in the .csproj project file, replacing theOctokittenApp
package with your package dependency and1.0.0
with the version you want to use:<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>netcoreapp3.0</TargetFramework> <PackageId>OctocatApp</PackageId> <Version>1.0.0</Version> <Authors>Octocat</Authors> <Company>GitHub</Company> <PackageDescription>This package adds an Octocat!</PackageDescription> <RepositoryUrl>https://HOSTNAME/OWNER/REPOSITORY</RepositoryUrl> </PropertyGroup> <ItemGroup> <PackageReference Include="OctokittenApp" Version="12.0.2" /> </ItemGroup> </Project>
-
Install the packages with the
restore
command.dotnet restore
Troubleshooting
Your NuGet package may fail to push if the RepositoryUrl
in .csproj is not set to the expected repository .