CS2SX — Write Nintendo Switch Homebrew in C#

Neues Projekt.png

CS2SX — Write Nintendo Switch Homebrew in C#
A C#-to-C transpiler that builds ready-to-run .nro files


Have you ever wanted to write Switch homebrew but found C/C++ intimidating?
CS2SX lets you write standard C# and compiles it directly to a Nintendo Switch
.nro — no C knowledge required.​



You write this:

public class MyApp : SwitchApp
{
private int _x = 640, _y = 360;
private int _vx = 4, _vy = 3;

public override void OnInit() => Graphics.Init(1280, 720);

public override void OnFrame()
{
Graphics.FillScreen(Color.Black);

_x += _vx;
_y += _vy;
if (_x < 20 || _x > 1260) _vx = -_vx;
if (_y < 20 || _y > 700) _vy = -_vy;

Graphics.FillCircle(_x, _y, 20, Color.RGB(0, 200, 255));
Graphics.DrawText(10, 10, "Press + to exit", Color.White, 1);

if (Input.IsDown(NpadButton.Plus))
Environment.Exit(0);
}
}

Run cs2sx build and put your .nro on your switch.


How it works

CS2SX is a transpiler — it reads your C# source using Roslyn (the official
Microsoft compiler frontend), converts it to clean C, and then hands it off to
DevkitPro's aarch64 GCC to produce the final .nro.

build.png


The entire workflow is one command:

cs2sx new MyApp # scaffold a new project
cs2sx build MyApp.csproj # transpile → compile → package → .nro

Copy the .nro to /switch/MyApp/ on your SD card and launch it from the
Homebrew Menu. That's it.




What C# features are supported?

CS2SX supports a large and practical subset of C#:

  • Full OOP — classes, inheritance, abstract/virtual/override, interfaces, generics
  • Collections — List<T>, Dictionary<K,V>, Stack<T>, Queue<T>, HashSet<T>
  • LINQ — Where, Select, OrderBy, GroupBy, First, Sum, Any, All and 30+ more
  • Strings — interpolation, Trim/Replace/Split/Join, StringBuilder
  • Value types — struct, enum, Nullable<T>, tuple returns
  • Modern syntax — pattern matching, switch expressions, ??, ?.
  • Extension methods, params[], ref/out parameters



Graphics & Input

CS2SX ships a built-in 2D framebuffer API:

// Shapes, text, textures
Graphics.FillRect(100, 100, 400, 200, Color.RGB(30, 30, 80));
Graphics.FillCircle(640, 360, 80, Color.Green);
Graphics.FillTriangle(900, 150, 1100, 150, 1000, 300, Color.Orange);
Graphics.DrawText(10, 10, $"Score: {_score}", Color.White, 2);
Graphics.DrawTextShadow(10, 50, "Shadow text", Color.White, Color.Black, 2);

// Load BMP textures from romfs (embedded in the .nro)
Texture icon = Graphics.LoadTexture("romfs:/icon.bmp");
Graphics.DrawTextureCenteredScaled(icon, 0, 0, 1280, 720, 128, 128);

// Buttons, analog sticks, touch screen
if (Input.IsDown(NpadButton.A)) Jump();
if (Input.IsHeld(NpadButton.ZR)) Shoot();
StickPos stick = Input.GetStickLeft();
TouchState touch = Input.GetTouch();
if (touch.count > 0)
Graphics.FillCircle(touch.X0, touch.Y0, 30, Color.Red);




Project structure

A CS2SX project is a standard .csproj you can open in Visual Studio or Rider —
with full IntelliSense, autocomplete and error highlighting.

MyApp/
├── MyApp.csproj ← open in any IDE
├── cs2sx.json ← app name, author, icon
├── MyApp.cs ← your code
├── icon.jpg ← 256×256 app icon
└── romfs/ ← assets embedded in .nro (BMPs, etc.)

cs2sx.json:
{
"name": "MyApp",
"author": "YourName",
"version": "1.0.0",
"icon": "icon.jpg"
}




Requirements

- .NET 8 SDK
- devkitA64 + libnx
- Environment variable DEVKITPRO set to your DevkitPro install path

//Install CS2SX via dotnet
dotnet pack -c Release
dotnet tool install --global --add-source ./bin/Release CS2SX




Known limitations

Being honest up front:

  • One SwitchApp subclass per project (the main entry point)
  • Interpolated strings ($"...") create stack buffers — safe in locals and output calls, but don't store them in fields
  • No garbage collector — heap objects live until freed (the transpiler handles this automatically for most cases)
  • async/await compiles synchronously
  • No Reflection



Source & Download

CS2SX is fully open source under the MIT license.

Download on Github:
Here you can see the Github page and releases

Example Projects:
Here you can see example Projects build with CS2SX

Issues, PRs and feature requests are welcome.
If you build something with it, I'd love to see it posted here!




Built with Roslyn · DevkitPro · libnx
 
@Cybercom684
Could you please upload all the Games section (PacMan, Pong, Snake, Space Invader and Tetris) in *.NRO format, as a compiled releases?.. Not just it's source code, but already built. Thank you!
 
@Cybercom684
Could you please upload all the Games section (PacMan, Pong, Snake, Space Invader and Tetris) in *.NRO format, as a compiled releases?.. Not just it's source code, but already built. Thank you!
Sure — I’ll upload the compiled ".nro" releases for all games (PacMan, Pong, Snake, Space Invader and Tetris) to their respective project folders within the next few days.
Post automatically merged:

@Cybercom684
Could you please upload all the Games section (PacMan, Pong, Snake, Space Invader and Tetris) in *.NRO format, as a compiled releases?.. Not just it's source code, but already built. Thank you!
You can now find the respective .nro in each project (excluding the basic/fundamentals projects) B-)
 
Last edited by Cybercom684,
  • Like
Reactions: mathew77
@Cybercom684
Thank you!..
Some screenshots of your games for examples:
 

Attachments

  • scr (1).jpg
    scr (1).jpg
    71 KB · Views: 1
  • scr (2).jpg
    scr (2).jpg
    13 KB · Views: 1
  • scr (3).jpg
    scr (3).jpg
    11.2 KB · Views: 2
  • scr (6).jpg
    scr (6).jpg
    23.8 KB · Views: 2
  • scr (4).jpg
    scr (4).jpg
    40.2 KB · Views: 1
  • Like
Reactions: Cybercom684
screen.png



I tested CS2SX in a dual Nintendo Switch homebrew setup next to a native libnx/devkitA64 starter, and I think the project has a very useful niche: not as a replacement for native libnx, but as a C# frontend for fast Switch prototyping.

My setup was Windows with devkitPro/devkitA64, CS2SX 0.4.3.819, and testing through Eden.

For ports and performance-heavy code, native libnx still feels like the right core path. But for AI-assisted experiments, menu prototypes, text UI, small tools, and simple gameplay logic, CS2SX could be very valuable because C# is much easier to generate, inspect, and restructure quickly.

A few practical findings from my setup:

  • The Text-UI/Form path produced visible output in Eden.
  • A minimal working pattern was to use local Label variables and pass them into Form.Add(...).
  • Using Label fields caused generated Label_Free(...) calls, but my installed runtime/build did not appear to provide Label_Free.
  • The framebuffer/Graphics path built successfully, but initially showed a black screen in Eden in my setup. This may be emulator/setup-specific, but a known-good Graphics smoke test would help.
  • Deleting stale cs2sx_out and old .nro files before rebuilds made testing much more reliable.
  • A generated Program.c verification step is useful to make sure the build is not using stale/default output.
  • A very small known-good visible smoke test would probably help new users a lot, especially one for Text-UI/Form and one for Graphics/framebuffer.
The bigger potential I see is CS2SX as an AI-friendly prototyping layer on top of the real devkitA64/libnx backend:






UPDATE:
Small CS2SX test update.





0000000000000000_2026-05-28_19-29-23-113.png



I have been testing CS2SX as a C#-to-Switch-homebrew prototyping layer on top of the normal devkitA64/libnx backend. My goal was not to make a finished app yet, but to see how practical it is to take the examples, modify them, build them as .nro files and run them in Eden / Homebrew Menu style.

First I made a very small custom demo:

- custom icon
- 256×256 pixel-art sprite
- romfs asset loading
- clean .nro build
- clean Homebrew Menu return on exit

One important finding there was the exit behavior. Calling `Environment.Exit(0)` from inside `OnFrame()` caused an error dialog on exit on original switch hardware. Removing that call and letting the normal CS2SX app loop handle `+` fixed it. After that the demo closed cleanly and returned to the Homebrew Menu.

After that I tested the CS2SX example projects. Most built directly, but a few needed local workarounds before they would build and boot:

- `HelloWorld_Konsole`
- `textEditor`
- `multiWindow`

The issues I ran into were mostly useful CS2SX edge cases:

- `Label` fields generated `Label_Free(...)`, but the runtime I had did not provide that function.
- a `FirstOrDefault(...)` predicate/lambda case generated invalid C where a void function was used like a bool.
- `TouchState` field assignments generated pointer-style C access even though the type was emitted as a value type.
- some field initializers and delegate-style callbacks in `multiWindow` needed to be simplified.

After working around those locally, I used the `multiWindow` example as a base for a small visual fork.

Current result:

- original multiWindow desktop/window concept is still there
- custom Evilengine pixel-art background
- bottom hacktro-style rainbow wave scroller
- small original chiptune-like tone motif
- startup cleaned up so the Info window is not forced open
- public package can be kept minimal: .nro + README + hash only

This was interesting because it showed two different workflows:

1. Start from scratch with a very small CS2SX app.
2. Take an existing CS2SX example and modify it into something more personal.

For me, the second route was more fragile because I had to work around some generator/runtime edge cases, but it also showed that the workflow is possible. For simple UI experiments, small demos, tools, menus, text effects and prototype logic, CS2SX feels promising. For lower-level or performance-heavy work, native libnx still seems like the more direct route.

Overall, this feels like a useful prototyping path, especially when using AI to help restructure C# logic quickly while still producing real Switch homebrew .nro builds through the devkitA64/libnx backend.

Here is the current Evilengine multiWindow fork test state:
- tiled pixel-art backdrop
- working windows
- scrolling rainbow text band
- simple chiptune-style audio
- clean enough to use as a small visual example

C# → CS2SX → generated C → libnx/devkitA64 → .nro

That is a very interesting workflow for quick iteration, especially when using AI tools to generate and revise prototype code.
 

Attachments

Last edited by Evilengine,
  • Like
Reactions: Cybercom684

Site & Scene News

Popular threads in this forum