C# Single File Execution with .NET 10

Recently, I got a message from the head of my kids’ kindergarten. They said the school will move from using Lyfle to Twigsee. Lyfle is an app for preschool communication, where teachers and parents can share updates, events, and most importantly, photos. Lots of photos. Three years’ worth of memories.

Before the switch, I wanted to back up all the photos from Lyfle. I planned to organize them by month, from September 2022 to June 2025. But I was too lazy to create all the folders manually. That would be 34 folders. That’s too many to click through one by one and… not fun :D

Then I remembered something cool: C# now supports single file execution in .NET 10 (still in preview). It’s like writing a PowerShell script, but in C#. No need to create a full project with folders and boilerplate code. Just write a .cs file and run it directly.

I found the official announcement here: https://devblogs.microsoft.com/dotnet/announcing-dotnet-run-app/

So I installed the .NET 10 preview SDK. Then I asked GitHub Copilot to help me write a simple script. The script created folders for each month between September 2022 and June 2025. Thanks to GitHub Copilot, I could download the generated class directly, no need to copy and paste or manually create a new .cs file.

using System;
using System.IO;

DateTime start = new DateTime(2022, 9, 1);
DateTime end = new DateTime(2025, 6, 1);

for (DateTime dt = start; dt <= end; dt = dt.AddMonths(1))
{
    string folderName = dt.ToString("yyyy-MM");
    Directory.CreateDirectory(folderName);
    Console.WriteLine($"Created directory: {folderName}");
}

I just ran it on CMD like this:

dotnet run CreateMonthlyFolders.cs

Boom. All the folders were created in seconds. It felt like magic. If you check the logs, you’ll see that .NET compiles the script behind the scenes and runs it just like a regular app. But from the outside, it feels like scripting.

This new feature is great for quick tasks. It lowers the barrier for new developers to try C#. You don’t need to understand how to create a project or deal with .csproj files. Just write and run.

One funny thing though: I now have all the folders, but the photos are still not downloaded. So the backup is… halfway done. I guess that’s my next task.

Still, I’m excited about where C# is going. This small feature made my life easier, and I think it will help others too.