Golang to C# Converter
Browse all: Go Standard Library NuGet packages
204 of the 215 testable standard-library packages pass their own Go test suites in C# — 28,459
matching verdicts against go test -json, compared verdict for verdict, with 167 divergences
disclosed by exact failure signature and nothing else waived. Six of those 215 cannot be validated
at all — no eligible tests on this platform, a broken upstream oracle, a suite whose whole subject
is the raw memory layout a managed runtime deliberately does not have, or a comparison that runs
cleanly and validates nothing — so the honest denominator is 209, putting the roster at 97.6%.
Each of the six is listed with its class, mechanism and evidence in the
exclusion ledger, and any one of them rejoins the
count the day its evidence changes. On Linux, 198 of the 202 applicable rows validate at their own
Linux counts. A package appears on the roster only when every eligible
test agrees, and every row links a proof page listing Go's verdict beside
go2cs's, test by test.
Those figures are the Go 1.23.12 anchor — a closed record rather than a running total. The corpus now moves to Go 1.24.13, and a version hop re-derives every roster row from the new release's own test sources, so the five packages still unbanked here re-validate there on exactly the footing of the 204 that banked. The 1.23.12 corpus ships one final NuGet release first, freezing its roster, its proof pages and every package README at the record above — see the announcement.
➡ All announcements can be found in the go2cs News Archive.
Convert source code written in the Go programming language into C#. The generated C# is designed to be both behaviorally and visually similar to the original Go — so a Go developer can read the converted code and follow it easily, and a .NET developer can use Go code directly within the .NET ecosystem.
utf8_test.csGo leans on its compiler and runtime for slices, maps, channels, goroutines, defer/panic/recover,
multiple returns, struct embedding and interface duck-typing. go2cs maps each onto idiomatic C#, keeping
the machinery out of sight — in a small runtime library and compile-time source generators — so the
converted code stays close to the original Go.
goroutine runs on the
thread pool rather than being rewritten into async).Given this Go:
type Person struct {
name string
age int32
}
func (p Person) IsAdult() bool {
return p.age >= 18
}go2cs produces this C#:
[GoType] partial struct Person {
internal @string name;
internal int32 age;
}
public static bool IsAdult(this Person p) {
return p.age >= 18;
}The goal — reads like Go — is easiest to judge on real code. Below are converted standard-library files next to their original Go 1.23.12 source, in order of increasing richness:
| Package | Go 1.23.12 source | Converted C# | What it shows |
|---|---|---|---|
errors |
errors.go | errors.cs | Error values and an unexported type satisfying the error interface. |
cmp |
cmp.go | cmp.cs | Generics with an ordered-type constraint. |
unicode/utf8 |
utf8.go | utf8.cs | Constants keeping Go's hex/binary literal formatting; arrays and structs. |
sort |
search.go | search.cs | Binary search driven by a func(int) bool closure. |
strings |
reader.go | reader.cs | A struct with receiver methods, tuple returns, and interface implementation. |
container/list |
list.go | list.cs | A doubly-linked list — pointers and receiver methods. |
Browse the whole set under src/core.
go2cs converts the full Go language surface — the same converter that emits the 302 packages above:
Types & values
@stringint / uint as platform-width native integers; named numeric types and untyped-constant semanticsiota, preserving Go's numeric literal formatting (hex, binary, underscores, exponents)nil; unsafe.PointerFunctions & methods
defer / panic / recover, including named results observed and mutated by deferred closuresConcurrency
async)| Package deadline for a converted-test action, in Go duration syntax (default `2m`). For `run`/`compare` it is handed to **both** sides — `go test -timeout` and the converted host's own `-timeout` — so they agree. A suite that legitimately runs long needs a value above both defaults: `hash/maphash` takes ~15 minutes in C# where Go's takes 7.6 seconds, so it is validated with `-test-timeout 30m`. | | `-go2cspath ` | Runtime/stdlib root (env `GO2CSPATH`; default `~/go2cs`) used by generated `$(go2csPath)…` references, and the output root for `-stdlib`. For a single-package/file conversion, C# output goes to optional `[output_dir]` (in place by default). | | `-goroot` / `-gopath` | Override the detected Go root / path. | | `-platforms ` | Target platform for build-tagged files (defaults to the host). A comma-separated **list** (`windows/amd64,linux/amd64,darwin/amd64`) is accepted and today requires `-platform-census`: a conversion still emits for exactly one target, so a list without the census flag is rejected rather than silently converting the first. | | `-platform-census ` | With `-stdlib` and two or more `-platforms` targets: convert once per target into an isolated, seeded staging root under, compare what each run actually emitted, and write \platform-manifest.json classifying every artifact as shared, variant, partial or platform-exclusive. Produces no converted output of its own — -go2cspath is read as the seed and never written to. |
| -tags | Build tags applied when loading packages. -stdlib and -tests apply purego by default; an explicit value replaces it. |
| -indent | Spaces per indent level (default 4). |
| -var | Prefer var declarations where the type is obvious (default on). |
| -uco | Emit channel operators instead of method calls (default on). |
| -comments | Carry source comments into the output (best effort, see go/ast comment status). |
| -csproj | Generate project files from a custom .csproj template instead of the embedded one. |
| -tree | Print each file's Go parse tree (go/ast) to stdout during conversion — a diagnostic aid. |
| -debug | Disable the converter's per-file panic recovery, so a conversion failure crashes with a full stack trace instead of being reported as a warning. |
| -cgoimport "C" ladder (P/Invoke-backed, staged after the current validation campaign), and this flag comes alive with it. |All converted C# code references a hand-written runtime library (golib, published as the go.lib
NuGet package) plus a set of Roslyn source generators that supply Go semantics at compile time (published as
go.gen). A -recurse=nuget conversion wires both up for you.
The -recurse option converts a whole downloaded application together with every third-party dependency
package in its transitive import closure — in dependency order (least-dependencies-first) — while
referencing (not reconverting) the pre-converted standard library. The result is a C# solution you can
open and build. With -recurse=nuget the standard library, the golib runtime and the go2cs-gen
analyzer come from nuget.org, so nothing has to
be staged on the machine beforehand. (Prefer the standard library as local C# source? See
building against a local standard library below.)
Wondering which real-world Go packages make good conversions? The go2cs Target Atlas surveys the Go ecosystem's best candidates — the study behind the first operational package conversions now being planned.
Here is the full round-trip for a small CLI that uses github.com/fatih/color,
which itself pulls in `github.com/mattn/go-color
No open issues yet, or sync has not completed.