Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@droidsolutions-oss/semantic-release-nuget

Package Overview
Dependencies
Maintainers
2
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@droidsolutions-oss/semantic-release-nuget

Semantic Release plugin to create and publish NuGet packages.

  • 2.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
264
increased by26.92%
Maintainers
2
Weekly downloads
 
Created
Source

semantic-release-nuget

semantic-release plugin to create and publish a NuGet package.

StepDescription
verifyConditionsVerify the presence of the NUGET_TOKEN environment variable and the presence of the dotnet executable as well as 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
nugetServerThe URL of the NuGet server to push the package to.https://api.nuget.org/v3/index.json
projectPathThe relative path to the project file to pack. Can also be an array including multiple projects.
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
publishToGitLabIf 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
skipPublishToNugetIf 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.

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.

Note: If skipPublishToNuget is set the package will not be published to the nuget server even if you specified an alternative via nugetServer. This only makes sense in combination with publishToGitLab.

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 to a token that has access to it and also gitlabUser must be set to the user the token belongs to.

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.

Example config

The following is an example how to use this plugin to build semantic versioned NuGet packages. 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
  "nugetServer": "https://nuget.mycomapny.com/v3/index.json", // custom (private) NuGet server
  "projectPath": "src/DroidSolutions.Oss.JobService/DroidSolutions.Oss.JobService.csproj", // path to the project files
  "includeSymbols": true, // include Debug symbols for easier debugging
  "publishToGitLab": true, // also publish the package to your GitLab server
  "files": [
    {
      "path": ["Directory.Build.props"], // configure update-file plugin to update fields in Directory.Build.props
      "type": "xml",
      "replacements": [
        {
          "key": "VersionPrefix",
          "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"
  ]
}

All NuGet packages will be in the out directory in project root and will be uploaded to the NuGet registry.

Keywords

FAQs

Package last updated on 10 Jan 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc