How to Publish a NuGet Package

How to Publish a NuGet Package

Command line

To push packages to nuget.org you must use nuget.exe v4.1.0 or above, which implements the required NuGet protocols. You also need an API key, which is created on nuget.org.

Create API keys

  1. Sign into your nuget.org account or create an account if you don't have one already.

    For more information on creating your account, see Individual accounts.

  2. Select your user name (on the upper right), then select API Keys.

  3. Select Create, provide a name for your key, select Select Scopes > Push. Enter * for Glob pattern, then select Create. (See below for more about scopes.)

  4. Once the key is created, select Copy to retrieve the access key you need in the CLI:

    Copying the API key to the clipboard

  5. Important: Save your key in a secure location because you cannot copy the key again later on. If you return to the API key page, you need to regenerate the key to copy it. You can also remove the API key if you no longer want to push packages via the CLI.

Scoping allows you to create separate API keys for different purposes. Each key has its expiration timeframe and can be scoped to specific packages (or glob patterns). Each key is also scoped to specific operations: push of new packages and updates, push of updates only, or delisting. Through scoping, you can create API keys for different people who manage packages for your organization such that they have only the permissions they need. For more information, see scoped API keys.

Publish with nuget push

  1. At a command prompt, run the following command, replacing <your_API_key> with the key obtained from nuget.org:

    cli
  • nuget setApiKey <your_API_key>
    

    This command stores your API key in your NuGet configuration so that you need repeat this step again on the same computer.

  • Push your package to NuGet Gallery using the following command:

    cli
nuget push YourPackage.nupkg -Source https://api.nuget.org/v3/index.json
原文地址:https://www.cnblogs.com/chucklu/p/11445857.html