BitbucketServer.Net
0.2.0
dotnet add package BitbucketServer.Net --version 0.2.0
NuGet\Install-Package BitbucketServer.Net -Version 0.2.0
<PackageReference Include="BitbucketServer.Net" Version="0.2.0" />
<PackageVersion Include="BitbucketServer.Net" Version="0.2.0" />
<PackageReference Include="BitbucketServer.Net" />
paket add BitbucketServer.Net --version 0.2.0
#r "nuget: BitbucketServer.Net, 0.2.0"
#:package BitbucketServer.Net@0.2.0
#addin nuget:?package=BitbucketServer.Net&version=0.2.0
#tool nuget:?package=BitbucketServer.Net&version=0.2.0
Bitbucket.Net
Modernized C# client for Bitbucket Server (Stash) REST API.
Contributing
Development setup (including the pre-commit formatting hook) is documented in CONTRIBUTING.md.
Fork notice — This is an actively maintained fork of lvermeulen/Bitbucket.Net, which appears to be abandoned (last release 2020). The library is at 0.x — the API surface may still change between minor versions. It is used in production by the author (as the backend for an MCP Server talking to on-prem Bitbucket Server), but not every endpoint has been verified against a live instance. Contributions, bug reports, and feedback are very welcome.
What changed from the original
- .NET 10 target (dropped .NET Framework / .NET Standard)
System.Text.Jsoninstead of Newtonsoft.Json (2-3x faster, no CVEs)CancellationTokenon every async methodIAsyncEnumerablestreaming for paginated endpoints- Streaming diffs and raw file content
- Typed exception hierarchy (
BitbucketNotFoundException, etc.) IHttpClientFactory/ DI-friendly constructors- Bitbucket Server 9.0+ blocker-comment (task) support with legacy fallback
- Flurl.Http 4.x
If you're looking for Bitbucket Cloud API, try this repository.
Installation
dotnet add package BitbucketServer.Net
Usage
Basic Authentication
var client = new BitbucketClient("https://bitbucket.example.com", "username", "password");
Token Authentication
var client = new BitbucketClient("https://bitbucket.example.com", () => GetAccessToken());
Dependency Injection with IHttpClientFactory
For production scenarios, you can inject an externally managed HttpClient to leverage IHttpClientFactory for connection pooling, resilience policies (via Polly), and centralized configuration:
// In Program.cs or Startup.cs
services.AddHttpClient<BitbucketClient>(client =>
{
client.Timeout = TimeSpan.FromMinutes(2);
})
.AddTransientHttpErrorPolicy(p =>
p.WaitAndRetryAsync(3, retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt))))
.AddTransientHttpErrorPolicy(p =>
p.CircuitBreakerAsync(5, TimeSpan.FromSeconds(30)));
// Register BitbucketClient
services.AddSingleton<BitbucketClient>(sp =>
{
var httpClientFactory = sp.GetRequiredService<IHttpClientFactory>();
var httpClient = httpClientFactory.CreateClient(nameof(BitbucketClient));
return new BitbucketClient(
httpClient,
"https://bitbucket.example.com",
() => sp.GetRequiredService<ITokenProvider>().GetToken());
});
Advanced: Using IFlurlClient
For fine-grained control over Flurl's configuration:
services.AddSingleton<IFlurlClientCache>(sp => new FlurlClientCache()
.Add("Bitbucket", "https://bitbucket.example.com", builder => builder
.WithSettings(s => s.Timeout = TimeSpan.FromMinutes(5))
.WithHeader("X-Custom-Header", "value")));
services.AddSingleton<BitbucketClient>(sp =>
{
var flurlClient = sp.GetRequiredService<IFlurlClientCache>().Get("Bitbucket");
return new BitbucketClient(flurlClient, () => GetToken());
});
Streaming with IAsyncEnumerable
For memory-efficient processing of large result sets, use the streaming variants:
// Stream projects without buffering all pages in memory
await foreach (var project in client.GetProjectsStreamAsync())
{
Console.WriteLine(project.Name);
}
// With cancellation support
var cts = new CancellationTokenSource(TimeSpan.FromMinutes(5));
await foreach (var pr in client.GetPullRequestsStreamAsync("PROJ", "repo", cancellationToken: cts.Token))
{
await ProcessPullRequestAsync(pr);
}
// Stream PR activities
await foreach (var activity in client.GetPullRequestActivitiesStreamAsync(
"PROJ", "repo", pullRequestId: 42))
{
ProcessActivity(activity);
}
// Stream dashboard PRs
await foreach (var pr in client.GetDashboardPullRequestsStreamAsync())
{
Console.WriteLine($"#{pr.Id}: {pr.Title}");
}
Exception Handling
The library provides typed exceptions for precise error handling:
try
{
var repo = await client.GetRepositoryAsync("PROJ", "repo");
}
catch (BitbucketNotFoundException ex)
{
Console.WriteLine($"Repository not found: {ex.Context}");
}
catch (BitbucketAuthenticationException)
{
Console.WriteLine("Invalid credentials");
}
catch (BitbucketForbiddenException ex)
{
Console.WriteLine($"Access denied: {ex.Message}");
}
catch (BitbucketApiException ex)
{
Console.WriteLine($"API error {ex.StatusCode}: {ex.Message}");
}
Benchmarks
Performance benchmarks are available in the benchmarks/ folder using BenchmarkDotNet:
cd benchmarks/Bitbucket.Net.Benchmarks
dotnet run -c Release
See benchmarks/README.md for detailed instructions.
Features
- Audit
- Project Events
- Repository Events
- Branches
- Create Branch
- Delete Branch
- Branch Info
- Branch Model
- Builds
- Commits Build Stats
- Commit Build Stats
- Commit Build Status
- Associate Build Status
- Comment Likes
- Repository Comment Likes
- Pull Request Comment Likes
- Core
- Admin
- Groups
- Users
- Cluster
- License
- Mail Server
- Permissions
- Pull Requests
- Application Properties
- Dashboard
- Groups
- Hooks
- Inbox
- Logs
- Markup
- Profile
- Projects
- Projects
- Permissions
- Repos
- Repos
- Branches
- Browse
- Changes
- Commits
- Compare
- Diff
- Files
- Last Modified
- Participants
- Permissions
- Pull Requests
- Raw
- Settings
- Tags
- Webhooks
- Settings
- Repos
- Tasks
- Users
- Admin
- Default Reviewers
- Project Default Reviewers
- Repository Default Reviewers
- Git
- JIRA
- Create JIRA Issue
- Get Commits For JIRA Issue
- Get JIRA Issues For Commits
- Personal Access Tokens
- Ref Restrictions
- Project Restrictions
- Repository Restrictions
- Repository Ref Synchronization
- SSH
| 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
- Flurl.Http (>= 4.0.2)
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 |
|---|---|---|
| 0.2.0 | 0 | 2/8/2026 |
| 0.1.0-beta.1 | 30 | 2/6/2026 |