Compile C# Project into single file

Hey ho there! I love this site! I’m currently working on the Mars Lander, and it’s and incredibly satisfying task to tackle! However, managing a code base consisting of hundreds of lines of code in a single file is incredibly frustrating and confusing. For that reason, I have written a quick program that allows you to store your files anywhere and have them compiled into something that the CodinGame environment can use.
You can find the code here:
Just grab the zip in the releases section if you want to get straight to it. You will need to run Application.exe in the terminal, e.g.
Application.exe -w WorkingDirectory -e EntryFile -o OutputFile
From the WorkingDirectory on, all files will be watched for changes
From the EntryFile on, all namespaces will be searched and imported into the output file
The OutputFile is the file that will be created and overridden with the single file content
Bear in mind that I’ve had some issues if my EntryFile was in the same folder with other cs files. I generally have a structure where my main file calls code from nested folders e.g. a folder for MarsLander, or some other game, etc.
I think that’s it. You probably want to also make sure you have the CodinGame file watcher extension, so that your code is being synced with that file of yours, so you don’t have to copy the content yourself. Anyway, I think that’s it. Hope it helps someone!

EDIT: Oh, resource management was not a concern btw :smiley: So if the program eats your RAM I’m giving no warranty… O.o

1 Like

Wouldn’t it be easier to run a merging script in your post-build events instead of having that process running the whole time?

I guess I could add a parameter that would let the script only run a single time - that way, users could implement their own workflow in whatever way they see fit. The term compiler might be a bit misleading in the fact that nothing is actually being built, right. I’m just merging the text contents into a single file. So building the application and then merging the text content into a single file is creating a bunch of fluff that you technically don’t even need. But yeah, having it run the whole time is probably not smartest, it was just the most straight-forward for my personal use case. Thanks for the feedback!

Hi there,

I found it a bit hard to use your tool so I created my own simplistic version of it.
I put it here because it did the trick for me, so maybe it will also for some other people?

Anyway thx for the inspiration and here are some details to it:

For Windows users you can directly download the .zip, extract and run the tool:


# Minimal
.\CSharpSourcesToSingleFile.exe -o Filename.cs 
# Detailed 
.\CSharpSourcesToSingleFile.exe --output Filename.cs --directory ../workingdir/ --verbose

# More information with
.\CSharpSourcesToSingleFile.exe --help

P.S. : if you find some issues, feel free to report them or file a PR. I’ll try to fix it.

1 Like


A long time ago I’ve created a similar tool, and for the Spring Challenge this year I converted it into a NuGet package that adds it to the build process. This makes it much easier to set up a new CG project - compared to copying/downloading an exe and adding it to the post-build events manually.
It was made primarily for myself but I hope others can benefit as well. Suggestions and issue reports are most welcome!

The package is at NuGet Gallery | Jox.MergeCSharpFiles 0.5.2 , and the source code here:
GitHub - jopabe/codingame-utils

1 Like