TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Show HN: C# compiler with Go-like tooling (build small/standalone/native apps)

14 pointsby MStrehovskyalmost 4 years ago

1 comment

MStrehovskyalmost 4 years ago
As a C# dev I&#x27;m sometimes envious of the experience that Go devs have around building small selfcontained executables. Type a few lines into a .go file, `go build` the file and you have an executable that you can give to anyone and it runs (be it Ubuntu&#x2F;Alpine&#x2F;whatever). Yeah, with the default deployment model of C# it&#x27;s nice that you don&#x27;t have to worry about security vulnerabilities in your networking stack being unpatched until you rebuild your app (the networking stack is part of a runtime or other libraries that can be serviced independently from the app), but also not everything you build with C# is an internet-facing web server... and not everyone wants to carry a 20 MB runtime with a prerequisite list with their app.<p>.NET made huge progress since .NET Core (Linux support, single executable support, etc.) and I think it&#x27;s getting where I would like to see it, but I decided to &quot;help it&quot; a little with a different take on the tooling. It&#x27;s a prototype.<p>I took the experimental .NET AOT compiler (from Microsoft&#x27;s NativeAOT project), mixed it with Roslyn (the official C# compiler) and built a standalone compiler&#x2F;tool. I took out everything that people usually associate with C# (MSBuild, NuGet, the `dotnet` CLI) and left just the bare minimum: language and libraries.<p><pre><code> $ echo &#x27;System.Console.WriteLine(&quot;Hello world&quot;);&#x27; &gt;hello.cs $ bflat build hello.cs $ .&#x2F;hello Hello world </code></pre> The compiler can also crosscompile - just pass `--os` and `--arch` to specify the architecture.<p>It produces selfcontained native executables starting at ~730 kB for a Hello World referencing System.Console (uncompressed).<p>The compiler is self-hosted, so hopefully that&#x27;s a good enough proof that it can already be used to build things.<p>The compiler comes in a ZIP file that you just extract and put on your PATH. It doesn&#x27;t depend on anything else (no SDKs, no sysroot, no other tools).<p>You can target Linux already but there&#x27;s no Linux version of the compiler itself because of some integration problems I still need to sort our (see Issues in the repo).<p>Disclaimer: I work at Microsoft, but this project is my freetime activity I whipped out without consulting anyone at work.