@droidsolutions-oss/semantic-release-nuget

中文文档
2.1.2发布于 2026/10/27MITES Module构建来源已验证近 30 天下载 9386

Semantic Release plugin to create and publish NuGet packages.

原始使用文档
文档目录15 节
  1. Install
  2. Usage
  3. Configuration
  4. NuGet server authentication
  5. Environment Variables
  6. Options
  7. Versioning
  8. Config examples
  9. Simple publish to nuget.org
  10. Publish to current GitLab project
  11. Publish to a different GitLab project
  12. Publish to GitHub Packages
  13. Publish to multiple registries
  14. Persist version changes in Directory.Build.props
  15. Multiple packages

semantic-release-nuget

semantic-release plugin to create and publish NuGet packages.

NPM Version

StepDescription
verifyConditionsVerify the correctness of the provided plugin config.
prepareCreates NuGet packages.
publishPublishes the created NuGet packages to the given registries.

Install

Install the plugin as a development dependency with

npm i -D @droidsolutions-oss/semantic-release-nuget

Usage

The plugin can be configured in the semantic-release configuration file:

{
  "plugins": [
    "@semantic-release/commit-analyzer",
    "@semantic-release/release-notes-generator",
    "@semantic-release/changelog",
    "@droidsolutions-oss/semantic-release-update-file",
    "@semantic-release/npm",
    "@droidsolutions-oss/semantic-release-nuget",
    [
      "@semantic-release/git",
      {
        "assets": ["package.json", "package-lock.json", "CHANGELOG.md", "Directory.Build.props"],
        "message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
      }
    ],
    "@semantic-release/gitlab"
  ]
}

Hint: you can use the @droidsolutions-oss/semantic-release-update-file plugin to update the version number in a project or Directory.Build.props file before creating the NuGet package.

Configuration

NuGet server authentication

The NuGet server authentication is required and can be set via environment variables.

Environment Variables

VariableDescription
NUGET_TOKENNuGet token of the NuGet server you want to publish to, created on the NuGet API keys page.
CI_SERVER_URLIf you want to publish to your GitLab server, this needs to be set to the main url of the GitLab instance you are using. When running in GitLab CI this is already set by GitLab.
CI_PROJECT_IDIf you want to publish to your GitLab server, this needs to be set to the Id of the project you want to publish to. When running in GitLab CI this is already set to the project the pipleine runs in by GitLab.
CI_JOB_TOKENIf you want to publish to your GitLab server, this needs to be set. When running in GitLab CI this is already set by GitLab, but it only works when publishing to the same project the pipeline runs in.

Options

OptionsDescriptionDefault
nugetRegistriesA list of NuGet registry configurations to publish to.see below
nugetRegistries[].typeThe type of the NuGet registry. Possible values are nuget, gitlab_private, github.nuget
nugetRegistries[].nameName of the source for logging and recognition from nuget.config.nuget
nugetRegistries[].urlThe URL to the NuGet registry.https://api.nuget.org/v3/index.json
nugetRegistries[].userThe user to login to the NuGet registry.
nugetRegistries[].tokenEnvVarThe name of the environment variable that contains the password or token to authenticate against the NuGet registry.NUGET_TOKEN or CI_JOB_TOKEN for GitLab.
projectPathThe relative path to the project file to pack. Can also be an array including multiple projects.
nugetServerDeprecated, use nugetRegistries[].url instead. The URL of the NuGet server to push the package to.https://api.nuget.org/v3/index.json
includeSymbolsIf true an extra package with debug symbols will be created.false
includeSourceIf true source code will be included in the package which helps when consumers need to debug your library.false
dotnetThe path to the dotnet executable if not in PATH.dotnet
publishToGitLabDeprecated, use nugetRegistries instead. If true, package will also be published to the GitLab registry.false
usePackageVersionIf true, the new version from Semantic Release is directly given to dotnet pack command, else the version set in csproj or Directory.Build.props is used for the NuGet package.false
skipPublishToNugetDeprecated, use nugetRegistries instead. If true, the NuGet package will not be published to the nugetServer. You can use this together with publishToGitLab to only publish your package to the GitLab registry.false
gitlabRegistryProjectIdCan be set to publish the package to a different GitLab project. Only used when publishToGitLab is set to true.CI_PROJECT_ID
gitlabUserNeeded when publishing to a separate GitLab project. If using a deploy token, to name of the token must be given, when using a personal access token, the name of the user must be given.gitlab-ci-token
dotnetVerbosityOptional string to pass to the dotnet pack command as verbosity argument. See verbosity argument for valid values.

With 2.1.0 configuration approach changed. Now a nugetRegistries array can be given to configure each registry the packages should be published to.

An empty config will lead to this default config:

{
  "nugetRegistries": [
    {
      "name": "nuget",
      "url": "https://api.nuget.org/v3/index.json",
      "tokenEnvVar": "NUGET_TOKEN",
      "type": "nuget"
    }
  ]
}

Note: If publishToGitLab is set the environment variables for CI_SERVER_URL, CI_PROJECT_ID and CI_JOB_TOKEN must be set. If you are running in GitLab CI this is automatically set by GitLab for you. The nugetRegistries config will be appended with this:

{
  "name": "gitlab",
  "url": "${CI_SERVER_URL}/api/v4/projects/${CI_PROJECT_ID}/packages/nuget/index.json",
  "tokenEnvVar": "CI_JOB_TOKEN",
  "type": "gitlab_private"
}

Note: If skipPublishToNuget is set the package will not be published to the official nuget server. This only makes sense in combination with publishToGitLab. This is now deprecated, you should instead configure your registries via the nugetRegistries config.

Note: When you add the NPM plugin to update your package.json you should set npmPublish to false to prevent Semantic Release from trying to publish an NPM package.

Note: When you want to publish your package to a different GitLab project with gitlabRegistryProjectId make sure the NUGET_TOKEN is a token that has access to it and also gitlabUser must be set to the user the token belongs to.

See config examples below for more info.

Versioning

There are two ways how the version is set in the created NuGet package. The easiest way (e.g. in that it does not require any additional configuration) is to set usePackageVersion to true. This will give the version that Semantic Release calculated as the next one directly as an argument to the dotnet pack command (via the -p:PackageVersion=<version> argument). However this has the downside of your version not being persisted in your repository files.

The recommended way to have your package versioned is to have the version in your project file. You can use a Directory.Build.props file to set the same version for all projects in your repository. Add a VersionPrefix (or Version) tag to it and use the Semantic Release Update file plugin to update the version prior to creating the package. Make sure the update-file plugin is before the git plugin in the plugins list and add the project file or the Directory.Build.props to the assets list. See example config below.

Config examples

Simple publish to nuget.org

You don't need any config, just make sure the NUGET_TOKEN environment variable contains a valid token to publish to nuget.org.

If you want to use another environment variable or just explicitly configure it, you can use this:

{
  "nugetRegistries": [
    {
      "name": "nuget",
      "url": "https://api.nuget.org/v3/index.json",
      "tokenEnvVar": "NUGET_TOKEN",
      "type": "nuget"
    }
  ]
}

Publish to current GitLab project

If you want to publish to the current GitLab project without special permissions you can use the following minimal example:

{
  "nugetRegistries": [
    {
      "type": "gitlab_private"
    }
  ]
}

This will resolve the GitLab registry url from variables that are set in the GitLab CI: ${CI_SERVER_URL}/api/v4/projects/${CI_PROJECT_ID}/packages/nuget/index.json. It will set tokenEnvVar to CI_JOB_TOKEN which is sufficient to publish packages to the current project.

Publish to a different GitLab project

If you want to publish to a different GitLab project you probably need a GitLab token with the correct rights. Add the project id to the general config:

{
  "gitlabRegistryProjectId": 123,
  "nugetRegistries": [
    {
      "type": "gitlab_private"
    }
  ]
}

This will resolve the GitLab registry url from variables that are set in the GitLab CI: ${CI_SERVER_URL}/api/v4/projects/123/packages/nuget/index.json. It will set tokenEnvVar to NUGET_TOKEN which is sufficient to publish packages to the current project. You can also set tokenEnvVar yourself if you want to use a different environment variable.

Publish to GitHub Packages

To publish to GitHub Packages you can use the github type.

{
  "nugetRegistries": [
    {
      "type": "github"
    }
  ]
}

This will automatically resolve the registry URL to https://nuget.pkg.github.com/${GITHUB_REPOSITORY_OWNER}/index.json. It will use GITHUB_TOKEN environment variable for authentication and GITHUB_ACTOR as username. Make sure your workflow has packages: write permission.

Publish to multiple registries

If you want to publish to different registries you should set tokenEnvVar for each:

{
  "nugetRegistries": [
    {
      "name": "nuget",
      "tokenEnvVar": "NUGET_TOKEN",
      "type": "nuget"
    },
    {
      "name": "gitlab_private",
      "tokenEnvVar": "CI_JOB_TOKEN",
      "type": "gitlab_private"
    }
  ]
}

Persist version changes in Directory.Build.props

The following is an example how to use this plugin to build semantic versioned NuGet packages and persist the version in the project files. Add a Directory.Build.props to your project, depending if you want to share the values in multiple projects of the same repository it can be anywhere from project root to next to your csproj file. This file can and should contain some metadata about your NuGet package.

Note: Instead of this special file you can also add those properties directly in your csproj file. If you do so, make sure you change the path for the update file plugin accordingly.

<Project>
  <PropertyGroup>
    <Authors>Stefan Ißmer</Authors>
    <Description>Library for working with jobs that may be recurring in distributed systems and microservices.</Description>
    <Company>DroidSolutions GmbH</Company>
    <PackageLicenseFile>LICENSE</PackageLicenseFile>
    <PackageReadmeFile>README.md</PackageReadmeFile>
    <PackageReleaseNotes>https://github.com/droidsolutions/job-service/blob/main/CHANGELOG.md</PackageReleaseNotes>
    <SymbolPackageFormat>snupkg</SymbolPackageFormat>
    <RepositoryUrl>https://github.com/droidsolutions/job-service.git</RepositoryUrl>
    <PublishRepositoryUrl>true</PublishRepositoryUrl>
    <RepositoryType>git</RepositoryType>
    <RepositoryBranch>main</RepositoryBranch>
    <RepositoryCommit>209982581960ec4e7361ec556e51be4ebbee2052</RepositoryCommit>
    <Version>3.0.1</Version>
  </PropertyGroup>
</Project>

Now configure Semantic Release and use the update file plugin to update values in the file. Apart from the Version you can also update the commit hash and others. Refer to the update-file plugin documentation for a list of values you can use.

{
  // order of plugins is important, because it is the execution order
  "plugins": [
    "@semantic-release/commit-analyzer",
    "@semantic-release/release-notes-generator",
    "@semantic-release/changelog",
    "@droidsolutions-oss/semantic-release-update-file", // update version in Directory.Build.props
    "@semantic-release/npm", // update package.json
    "@droidsolutions-oss/semantic-release-nuget", // create nuget package
    [
      "@semantic-release/git",
      {
        "assets": [
          "package.json",
          "package-lock.json",
          "CHANGELOG.md",
          "Directory.Build.props", // add updated file to the Semantic Release commit
        ],
        "message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}",
      },
    ],
    "@semantic-release/gitlab",
  ],
  "npmPublish": false, // prevent creating NPM package
  "nugetRegistries": [
    {
      "name": "custom-nuget",
      "url": "https://nuget.mycomapny.com/v3/index.json", // custom (private) NuGet server, uses NUGET_TOKEN for auth
      "type": "nuget",
    },
  ],
  "projectPath": [
    "src/DroidSolutions.Oss.JobService/DroidSolutions.Oss.JobService.csproj", // path to the project files
  ],
  "includeSymbols": true, // include Debug symbols for easier debugging
  "files": [
    {
      "path": ["Directory.Build.props"], // configure update-file plugin to update fields in Directory.Build.props
      "type": "xml",
      "replacements": [
        {
          "key": "Version",
          "value": "${nextRelease.version}",
        },
        {
          "key": "RepositoryCommit",
          "value": "${CI_COMMIT_SHA}",
        },
      ],
    },
  ],
}

Multiple packages

You can build multiple NuGet packages from one repositories. To do this, specify the relative paths to the projects. Instead of

{
  "projectPath": "src/DroidSolutions.SemanticVersion/DroidSolutions.SemanticVersion.csproj"
}

you could also use something like this:

{
  "projectPath": [
    "src/DroidSolutions.Oss.JobService/DroidSolutions.Oss.JobService.csproj",
    "src/DroidSolutions.Oss.JobService.EFCore/DroidSolutions.Oss.JobService.EFCore.csproj",
    "src/DroidSolutions.Oss.JobService.Postgres/DroidSolutions.Oss.JobService.Postgres.csproj"
  ]
}

版本与发布记录

@droidsolutions-oss/semantic-release-nuget 共发布 29 个版本,首次发布于 2022/01/20;过去 12 个月发布了 10 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
2.1.2latest2026/10/2717 天前
2.1.12026/10/1628 天前
2.1.02026/05/215 个月前
2.1.0-beta.7beta2026/05/215 个月前
2.1.0-beta.62026/03/177 个月前
2.1.0-beta.52026/03/177 个月前

关于 @droidsolutions-oss/semantic-release-nuget 的常见问题

@droidsolutions-oss/semantic-release-nuget 是什么?

Semantic Release plugin to create and publish NuGet packages.

如何安装 @droidsolutions-oss/semantic-release-nuget?

在项目目录运行 npm install @droidsolutions-oss/semantic-release-nuget,或使用 pnpm add / yarn add / bun add。

@droidsolutions-oss/semantic-release-nuget 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/droidsolutions-oss__semantic-release-nuget 是否存在。

@droidsolutions-oss/semantic-release-nuget 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@droidsolutions-oss/semantic-release-nuget 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=22。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@droidsolutions-oss/semantic-release-nuget 可以商用吗?

@droidsolutions-oss/semantic-release-nuget 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@droidsolutions-oss/semantic-release-nuget 的下载量有多少?

根据 npm 官方下载统计,@droidsolutions-oss/semantic-release-nuget 在 2026/10/13 – 2026/11/11 这 30 天内被下载 9,386 次,日均约 313 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@droidsolutions-oss/semantic-release-nuget 还在维护吗?

最新版本 2.1.2 发布于 2026/10/27(17 天前);至今共发布 29 个版本,其中过去 12 个月发布了 10 个;首次发布于 2022/01/20。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。