Publish NuGet Packages
Suppose you have a NuGet package and want to publish it to the newly created NuGet feed by:
directly uploading the package to the feed,
using command-line tools like
dotnet
,nuget
orchocolatey
,
warning
Note that publishing packages with the same package version is not allowed. The server will return the 409 HTTP response.
The fastest way to publish a NuGet package is to directly upload it to a NuGet feed.
Open the Packages page and select the required NuGet feed.
Click the
Upload button in the top right corner.
Follow the instructions in the window.
The easiest way to publish a NuGet package to a feed is to run a one-line dotnet nuget push
, nuget push
or choco push
command. The feed's URL and credentials should be provided as command arguments.
note
If, during publishing, you authenticate using a token, you should use the
v2
feed URL instead ofv3
.
Typically, you should specify package name, the feed's URL, and a permanent access token. For example:
dotnet nuget push MyPackage.0.0.1.nupkg -s https://nuget.pkg.jetbrains.space/mycompany/p/projectkey/mynuget/v2/package -k access-token-goes-here
Typically, you should specify package name, the feed's URL, and a permanent access token. For example:
nuget push MyPackage.0.0.1.nupkg -Source https://nuget.pkg.jetbrains.space/mycompany/p/projectkey/mynuget/v2/package -ApiKey access-token-goes-here
Typically, you should specify the package name, the feed's URL, and a permanent access token. For example:
choco push MyPackage.0.0.1.nupkg -s https://nuget.pkg.jetbrains.space/mycompany/p/projectkey/mynuget/v2/package -k access-token-goes-here
If you don't want to provide credentials or an access token each time you access the feed, you can configure permanent access to the feed. There are several ways to do this:
You should provide feed URL and access credentials using the
dotnet nuget add source
command. For example:dotnet nuget add source https://nuget.pkg.jetbrains.space/mycompany/p/projectkey/mynuget/v3/index.json -n myNuget -u admin -p access-token-goes-here --store-password-in-clear-text
You should provide feed URL and access credentials using the
nuget sources add
command. For example:nuget sources add -name foo.bar -source https://nuget.pkg.jetbrains.space/mycompany/p/projectkey/mynuget/v3/index.json -username admin -password access-token-goes-here
You should provide the feed URL and access credentials using the
choco source add
command. For example:choco source add -name foo.bar -s https://nuget.pkg.jetbrains.space/mycompany/p/projectkey/mynuget/v3/index.json -u admin -p access-token-goes-here
Open the NuGet configuration file. By default, it's located at
Windows:
%appdata%\NuGet\NuGet.Config
macOS/Linux:
~/.config/NuGet/NuGet.Config
or~/.nuget/NuGet/NuGet.Config
In the
packageSources
section, specify the feed's URL.In the
packageSourceCredentials
section, specify credentials of either your own Space account (we recommend that you use a permanent token instead of a password) or a separate service account.The resulting configuration will look similar to the following one:
<configuration> <packageSources> <add key="space" value="https://nuget.pkg.jetbrains.space/mycompany/p/projectkey/mynuget/v3/index.json" protocolVersion="3"/> </packageSources> <packageSourceCredentials> <space> <add key="Username" value="admin"/> <add key="ClearTextPassword" value="access-token-goes-here"/> </space> </packageSourceCredentials> </configuration>
Alternatively, you can use Azure Artifacts Credential Provider. What this tool does is acquire and securely store a token any time you access a NuGet package from the feed.
Install the tool by downloading and running the helper script: installcredprovider.ps1 (Windows) or installcredprovider.sh (macOs, Linux).
Provide feed credentials. Here you have two options:
Save the credentials in environment variables.
Perform any operation that requires authorization. For example, run
dotnet restore --interactive
in the project directory ornuget restore
. The acquired token will be saved in the session token cache location.
For more information, refer to the tool documentation.
Once you set up the access to the feed, you can publish packages without specifying feed access credentials. For example:
dotnet nuget push MyPackage.0.0.1.nupkg
https://nuget.pkg.jetbrains.space/mycompany/p/projectkey/mynuget/v3/index.json
nuget push MyPackage.0.0.1.nupkg -Source
https://nuget.pkg.jetbrains.space/mycompany/p/projectkey/mynuget/v3/index.json
-ApiKey key
nuget push
ApiKey
key
ApiKey
nuget setapikey key -Source https://nuget.pkg.jetbrains.space/mycompany/p/projectkey/mynuget/v3/index.json
choco push MyPackage.0.0.1.nupkg -s
https://nuget.pkg.jetbrains.space/mycompany/p/projectkey/mynuget/v3/index.json
-k key
oco push
ApiKey
k
key
ApiKey
choco apikey add -s https://nuget.pkg.jetbrains.space/mycompany/p/projectkey/mynuget/v3/index.json -k key
For example, you have a TeamCity build configuration that builds a library and creates a NuGet package. Now, your task is to publish the package to a NuGet feed in Space Packages.
Add the NuGet feed to your build configuration. To do this:
Open build configuration settings.
In Build Features, choose Add build feature.
Choose the Nuget feed credentials feature and specify the feed's URL and service account credentials.
When adding a build step that should work with the feed, for example NuGet Publish, specify the feed's URL. TeamCity will automatically take credentials from the Nuget feed credentials feature.
Thanks for your feedback!