Workers 0.2.0
dotnet add package Workers --version 0.2.0
NuGet\Install-Package Workers -Version 0.2.0
<PackageReference Include="Workers" Version="0.2.0" />
<PackageVersion Include="Workers" Version="0.2.0" />
<PackageReference Include="Workers" />
paket add Workers --version 0.2.0
#r "nuget: Workers, 0.2.0"
#:package Workers@0.2.0
#addin nuget:?package=Workers&version=0.2.0
#tool nuget:?package=Workers&version=0.2.0
Workers
Write Cloudflare Workers in C# via WebAssembly.
using Workers;
public static class Worker
{
[FetchEvent]
public static Task<Response> FetchAsync(
Request request,
Env environment,
Context context)
{
return Task.FromResult(
Response.Text("Hello from C# on Cloudflare Workers."));
}
}
Usage
Workers are plain static methods marked with event attributes:
[FetchEvent]
public static Task<Response> FetchAsync(
Request request,
Env environment,
Context context)
The package includes Worker-native APIs for requests, responses, routing, bindings, Durable Objects, queues, R2, D1, KV, caches, sockets, email, and other Workers platform features.
Publishing
Publish with the browser-wasm runtime:
dotnet publish -c Release -r browser-wasm
Workers defaults to invariant globalization for smaller bundles. If your Worker needs culture-specific formatting or comparisons, set WorkersInvariantGlobalization to false.
Publishing writes a dist/ folder with the Worker module, runtime adapter, and _framework files for deployment with Wrangler.
Keep deployment settings like routes, bindings, migrations, vars, and observability in your Wrangler config.
For HTTP-only Workers that do not call platform bindings or helper APIs, set WorkersIncludePlatformApis to false to emit a smaller adapter.
Examples
Small standalone examples are in examples/. Each one has its own project file and wrangler.toml, so you can view or copy the shape you need.
| Example | Shows |
|---|---|
BasicResponse |
Plain text response |
JsonApi |
JSON response and request path |
Redirects |
Redirects from query parameters |
CorsHeaders |
CORS and response headers |
ProxyFetch |
Fetching another origin |
CacheApi |
Workers Cache API |
KvBinding |
KV namespace binding |
R2Binding |
R2 bucket binding |
QueueProducer |
Sending queue messages |
QueueConsumer |
Consuming queue messages |
ScheduledTask |
Cron/scheduled events |
HelloWorld |
Minimal router usage |
| 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
- Microsoft.NET.ILLink.Tasks (>= 10.0.8)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.