# Xmake Csharp

> Use when building C# projects with xmake — `.cs` sources with the Mono `mcs` or .NET `dotnet` toolchain, binary / library output, adding references, and mixing with native code via P/Invoke.

- **Type:** Skill
- **Install:** `agentstack add skill-xmake-io-xmake-skills-xmake-csharp`
- **Verified:** Yes — security-reviewed for prompt injection and unsafe behavior
- **Seller:** [xmake-io](https://agentstack.voostack.com/s/xmake-io)
- **Installs:** 0
- **Category:** [Agent Skills](https://agentstack.voostack.com/c/agent-skills)
- **Latest version:** 0.1.0
- **License:** Apache-2.0
- **Upstream author:** [xmake-io](https://github.com/xmake-io)
- **Source:** https://github.com/xmake-io/xmake-skills/tree/master/skills/languages/xmake-csharp

## Install

```sh
agentstack add skill-xmake-io-xmake-skills-xmake-csharp
```

Requires the [AgentStack CLI](https://agentstack.voostack.com/docs/cli). Works with Claude Code, Cursor, and any MCP-compatible agent.

## About

# Building C# with Xmake

Xmake drives the C# compiler (Mono `mcs` or modern .NET `csc`/`dotnet`) through a target model similar to C++.

## 1. Minimal project

```lua
add_rules("mode.debug", "mode.release")

target("hello")
    set_kind("binary")
    add_files("src/*.cs")
```

## 2. Target kinds

```lua
target("app")       set_kind("binary")       -- .exe
target("mylib")     set_kind("shared")       -- .dll (class library)
```

## 3. Toolchain

```bash
xmake f --toolchain=mcs                      -- Mono compiler
xmake f --toolchain=dotnet                   -- .NET SDK (csc)
```

Pin a specific install with `--sdk`:

```bash
xmake f --toolchain=dotnet --sdk=/usr/share/dotnet/sdk/8.0.100
```

## 4. References

```lua
target("app")
    add_files("src/*.cs")
    add_csflags("/reference:System.dll", "/reference:System.Core.dll")
    -- Or the modern, portable form:
    add_values("cs.references", "System.dll", "System.Core.dll")
```

For NuGet / .NET SDK projects, prefer a real `.csproj` consumed via `dotnet build` — xmake's direct C# support is best for small / standalone tools.

## 5. Mixing with native code (P/Invoke)

```lua
target("nativelib")
    set_kind("shared")
    add_files("native/*.c")

target("app")
    set_kind("binary")
    add_files("src/*.cs")
    add_deps("nativelib")
```

In `Program.cs`:

```cs
using System.Runtime.InteropServices;
class Program {
    [DllImport("nativelib")]
    static extern int hello(int x);
}
```

Xmake places `nativelib.dylib`/`.so`/`.dll` next to the managed binary so the runtime loader finds it.

## 6. Flags

```lua
target("app")
    add_files("src/*.cs")
    add_csflags("-unsafe", "-nowarn:1591")
```

`add_csflags` maps to C# compiler flags.

## Pitfalls

- **`xmake` is not `dotnet build`.** Complex .csproj projects (NuGet, SDK-style projects, Razor, WPF designers) should go through `dotnet build` inside a `task(...)` instead of xmake's native C# support.
- **Missing `System.dll` references.** Modern .NET Core doesn't need them (implicit); Mono does. Test with the toolchain you'll ship on.
- **Managed DLL + native DLL path mismatch.** P/Invoke lookups fail if the native DLL isn't on `PATH` or next to the .exe. Xmake's default placement handles the common case.

## When to branch out

- Native library interop → `xmake-targets`
- Packaging a C# app → `xmake-xpack`

## Source & license

This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.

- **Author:** [xmake-io](https://github.com/xmake-io)
- **Source:** [xmake-io/xmake-skills](https://github.com/xmake-io/xmake-skills)
- **License:** Apache-2.0

Install and usage instructions live in the source repository linked above.

## Pricing

- **Free** — Free

## Security capabilities

Automated source analysis of v0.1.0 — what this tool can access:

- **Network access:** no
- **Filesystem access:** no
- **Shell / process execution:** no
- **Environment & secrets:** no
- **Dynamic code execution:** no

*"Yes" means the capability is present in the source — more access means more to trust, not that it is unsafe.*


## Versions

- **0.1.0** — security scan: passed — Imported from the upstream source.

## Links

- Listing page: https://agentstack.voostack.com/l/skill-xmake-io-xmake-skills-xmake-csharp
- Seller: https://agentstack.voostack.com/s/xmake-io
- Browse the marketplace: https://agentstack.voostack.com/browse

---
Listed on AgentStack — the marketplace for AI agent skills and MCP servers. Every listing is security-reviewed. Creators keep 70%.
