Configuring NuGet to work with a SourceCraft registry
-
Create a personal access token (PAT).
-
Create environment variables named
REGISTRY_USERNAMEandREGISTRY_PASSWORDcontaining data for authentication with a personal access token (PAT):export REGISTRY_USERNAME="iam" export REGISTRY_PASSWORD="<personal_access_token>" -
Set up the NuGet configuration file:
dotnet CLINuGet CLIManuallyTo edit the NuGet configuration file using the dotnet CLI, run this command:
dotnet nuget add source "https://pkg.sourcecraft.tech/nuget/v3/<organization_slug>/<registry_ID>/index.json" \ -n "sourcecraft-registry" \ -u %REGISTRY_USERNAME% \ -p %REGISTRY_PASSWORD% \ --store-password-in-clear-text --protocol-version 3Tip
You can find the organization slug and registry ID on the registry page in the SourceCraft UI.
To edit the NuGet configuration file using the NuGet CLI, run the
nuget.exefile with the following parameters:nuget sources add -Name "sourcecraft-registry" \ -Source "https://pkg.sourcecraft.tech/nuget/v3/<organization_slug>/<registry_ID>/index.json" \ -Username "%REGISTRY_USERNAME%" \ -Password "%REGISTRY_PASSWORD%" \ -StorePasswordInClearText -ProtocolVersion 3Tip
You can find the organization slug and registry ID on the registry page in the SourceCraft UI.
-
Open the NuGet configuration file:
Note
When using the dotnet CLI, the configuration file is located at
~/.nuget/NuGet/NuGet.Config, while for the NuGet CLI, at~/.config/NuGet/NuGet.Config. -
Update the configuration in the file as follows:
<?xml version="1.0" encoding="utf-8"?> <configuration> <packageSources> <add key="sourcecraft-registry" value="https://pkg.sourcecraft.tech/nuget/v3/<organization_slug>/<registry_ID>/index.json" protocolVersion="3" /> </packageSources> <packageSourceCredentials> <sourcecraft-registry> <add key="Username" value="%REGISTRY_USERNAME%" /> <add key="ClearTextPassword" value="%REGISTRY_PASSWORD%" /> </sourcecraft-registry> </packageSourceCredentials> </configuration>Tip
You can find the organization slug and registry ID on the registry page in the SourceCraft UI.
-
-
To push the prepared NuGet package to a SourceCraft registry, run this command:
dotnet CLINuGet CLIdotnet nuget push <path_to_package> \ -s "sourcecraft-registry"nuget push <path_to_package> \ -Source "sourcecraft-registry"Result:
Pushing Nuget.Quickstart.1.0.0.nupkg to 'https://pkg.sourcecraft.tech/nuget/v3/myorg_cn10ckmq8hsk********/packages/'... PUT https://pkg.sourcecraft.tech/nuget/v3/myorg_cn10ckmq8hsk********/packages/ Created https://pkg.sourcecraft.tech/nuget/v3/myorg_cn10ckmq8hsk********/packages/ 1534ms Your package was pushed. -
To install the NuGet package from the SourceCraft registry, run this command:
dotnet CLINuGet CLIdotnet add package <package_name> \ --source "sourcecraft-registry"nuget install <package_name> \ -Source "sourcecraft-registry"
See also
- SourceCraft resource relationships
- Creating a registry in SourceCraft
- Connecting a registry to a SourceCraft repository
- Configuring Maven to work with a SourceCraft registry
- Configuring npm to work with a SourceCraft registry
- Configuring PyPI to work with the SourceCraft registry
- Configuring Docker to work with a SourceCraft registry