CP.Nuke.BuildTools
2.0.16
dotnet add package CP.Nuke.BuildTools --version 2.0.16
NuGet\Install-Package CP.Nuke.BuildTools -Version 2.0.16
<PackageReference Include="CP.Nuke.BuildTools" Version="2.0.16" />
<PackageVersion Include="CP.Nuke.BuildTools" Version="2.0.16" />
<PackageReference Include="CP.Nuke.BuildTools" />
paket add CP.Nuke.BuildTools --version 2.0.16
#r "nuget: CP.Nuke.BuildTools, 2.0.16"
#:package CP.Nuke.BuildTools@2.0.16
#addin nuget:?package=CP.Nuke.BuildTools&version=2.0.16
#tool nuget:?package=CP.Nuke.BuildTools&version=2.0.16
CP.Nuke.BuildTools
A collection of extension methods that simplify common build, packaging and release tasks when using Nuke Build.
Add the NuGet package to your build project (the one containing Build.cs):
dotnet add build/_build.csproj package CP.Nuke.BuildTools
Then add:
using CP.BuildTools; // at top of Build.cs
Extension Overview
The following extension methods are available (defined in build/Extensions.cs):
| Method | Purpose |
|---|---|
PublicNuGetSource() |
Returns the public NuGet v3 index URL. |
UpdateVisualStudio(version) |
Updates VS installation and applies common workloads. |
GetFileFromUrlAsync(url) |
Downloads text content from a URL. Returns empty string on blank URL. |
RestoreProjectWorkload(project) |
Runs dotnet workload restore for a single project. |
RestoreSolutionWorkloads(solution) |
Runs dotnet workload restore for the whole solution. |
GetPackableProjects(solution) |
Returns projects with IsPackable MSBuild property true. |
GetTestProjects(solution) |
Returns projects with IsTestProject MSBuild property true. |
InstallDotNetSdk(params versions) |
Installs SDK channels matching version patterns (e.g. 8.x.x, 9.0.100). |
GetAsset(repoOwner,repoName,assetName,releaseTag) |
Downloads a release asset from GitHub. |
SaveFile(path,bytes) |
Writes a file if it does not already exist. |
SetGithubCredentials(token) |
Sets credentials on Octokit client for later GitHub API calls. |
UploadReleaseAssetToGithub(release,assetPath) |
Uploads (or replaces) a single asset file into a draft release. |
UploadDirectory(release,directory) |
Uploads all root files in a directory as release assets. |
CreateRelease(repo,tag,version,commitSha,isPrerelease) |
Creates a draft GitHub release. |
AppendReleaseNotes(release,repo,maxCommits) |
Appends generated commit list to release body. |
Publish(release,repo) |
Publishes (un-drafts) a release. |
InstallAspNetCore(version) |
Installs ASP.NET Core runtime for a channel (>= 6). |
GenerateReleaseNotes(repo,maxCommits) |
Returns markdown listing recent commits. |
NOTE: Methods that execute external processes (
ProcessTasks.StartShell) or call GitHub API have side-effects and expect required tools (git, pwsh) and environment (GitHub PAT) to be available.
Usage Examples
Below are example targets you can integrate into your Build class.
1. Basic NuGet Source
Target Info => _ => _
.Executes(() =>
{
Log.Information("NuGet V3: {Source}", this.PublicNuGetSource());
});
2. Update Visual Studio & Workloads (CI environments)
Target SetupCI => _ => _
.Executes(async () =>
{
await this.UpdateVisualStudio(); // Enterprise by default
await this.InstallDotNetSdk("8.x.x", "9.x.x"); // install latest matching channels
this.InstallAspNetCore("8.0");
Solution.RestoreSolutionWorkloads();
});
3. Packing Projects
Target Pack => _ => _
.DependsOn(Compile)
.Executes(() =>
{
var packable = Solution.GetPackableProjects();
if (packable == null || packable.Count == 0)
{
Log.Warning("No packable projects found.");
return;
}
DotNetPack(s => s
.SetConfiguration(Configuration)
.CombineWith(packable, (ps, p) => ps.SetProject(p)));
});
4. Installing Specific SDK Channels
Target InstallSdks => _ => _
.Executes(async () =>
{
// Patterns: Major.Minor.Patch can use 'x' placeholders.
await this.InstallDotNetSdk("6.x.x", "7.x.x", "8.0.x", "9.0.100");
});
5. GitHub Release Automation
Requires a GitHub PAT exported as an environment variable (e.g. GITHUB_TOKEN).
[Parameter][Secret] readonly string GitHubToken;
[GitRepository] readonly GitRepository Repository;
Target Release => _ => _
.Requires(() => GitHubToken)
.Executes(() =>
{
this.SetGithubCredentials(GitHubToken);
// Create draft release
var tag = $"v{NerdbankVersioning.NuGetPackageVersion}";
var release = this.CreateRelease(Repository, tag, NerdbankVersioning.NuGetPackageVersion, null, isPrerelease: false);
// Append commit based notes
release = release.AppendReleaseNotes(Repository, maxCommits: 40);
// Upload artifacts (assumes Pack target already produced nupkgs)
var artifactsDir = RootDirectory / "output";
release.UploadDirectory(artifactsDir);
// Publish
release.Publish(Repository);
});
6. Downloading a Release Asset
Target FetchAsset => _ => _
.Requires(() => GitHubToken)
.Executes(() =>
{
this.SetGithubCredentials(GitHubToken);
var bytes = this.GetAsset("owner", "repo", "mytool.zip", uiReleaseTag: null); // latest release
var dest = RootDirectory / "temp" / "mytool.zip";
this.SaveFile(dest, bytes);
Log.Information("Saved asset to {Path}", dest);
});
7. Using Commit Release Notes Separately
Target Notes => _ => _
.Executes(() =>
{
var markdown = Repository.GenerateReleaseNotes(25);
File.WriteAllText(RootDirectory / "RELEASE_NOTES.md", markdown);
});
8. Clone External Repository (Shallow)
Target CloneExample => _ => _
.Executes(() =>
{
var targetDir = RootDirectory / "external";
targetDir.CreateDirectory();
targetDir.Checkout("https://github.com/owner/repo.git");
});
Error Handling & Notes
InstallDotNetSdkthrows if no matching stable versions are found.InstallAspNetCorethrows if version < 6 or cannot parse.CreateRelease,Publish,AppendReleaseNotesrequire a valid authenticated Octokit client (set viaSetGithubCredentials).- Network dependent methods (
GetFileFromUrlAsync, GitHub operations) should be wrapped with retry logic if used in unstable environments.
Suggested Target Ordering
A typical pipeline using these utilities:
SetupCI� ensure tooling & SDKs.Restore(standard Nuke restore + workloads if needed).Compile.Pack.Release(optional for main / tagged builds).
License
MIT � see LICENSE file.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Nuke.Common (>= 10.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 2.0.16 | 319 | 11/23/2025 |
| 1.0.94 | 1,667 | 1/16/2025 |
| 1.0.79 | 839 | 10/23/2024 |
| 1.0.44 | 2,653 | 1/22/2024 |
| 1.0.38 | 596 | 12/30/2023 |
| 1.0.36 | 514 | 12/4/2023 |
| 1.0.34 | 487 | 10/30/2023 |
| 1.0.32 | 533 | 9/25/2023 |
| 1.0.29 | 398 | 9/14/2023 |
| 1.0.14 | 601 | 7/29/2023 |
| 1.0.13 | 532 | 7/5/2023 |
| 1.0.9 | 419 | 6/25/2023 |
| 1.0.8 | 416 | 6/25/2023 |
| 1.0.7 | 419 | 6/25/2023 |
Compatability with Net 6 and net 7