
The world of .NET is in a constant state of evolution, with the pace of framework improvements steadily increasing, especially following the advent of the cross-platform .NET Core in 2016.
Over the past few years, Microsoft has been working hard to increase the adoption of the C# language among new software developers, who often choose languages that appear to be easier to get started with, such as Python.
In this article, I will demonstrate how the creation of the simplest possible C# “Hello World” program has changed from something that could be viewed as ‘verbose’ to newcomers, to a streamlined setup that requires nothing more than a single file to run the program.
Evolution
I’m not going to delve into a deep history lesson here, but let’s first take a quick look at where we’ve been and where Microsoft is now taking us in the latest version of .NET (.NET 10), which at the time of writing is due for release in November of this year (2025).
.NET Framework/Core
When developing .NET Framework and .NET Core (pre-.NET 5) software projects, the simplest possible C# program looked something like the following code snippet, typically contained in a ‘Program.cs’ file.
There isn’t too much code here (10 lines all in all); however, if you can imagine putting yourself in the shoes of someone new to programming, there are several concepts that need to be explained and questions that are likely to be raised right from the start.
For example, what is a namespace
?
What does internal
mean?
What about static
and void
?
This could appear to be somewhat trivial to an experienced C# software developer; however, it could be enough to discourage a newcomer from choosing to pursue the language further when comparing it to other options in the marketplace.
.NET 5+
.NET 5 introduced a radical new concept for C# developers: top-level statements.
With the introduction of the top-level statements feature, it became possible for the main Program.cs file that is part of the C# project to be as simple as the following.
That’s right, no class or Main
method needed! With this new feature, essentially all boilerplate could be removed, and it became possible to write a very simple program without any of the previous ceremony.
However, while the main program file was very minimalistic, there was still a need to include a project file in order to compile and run the program.
The screenshot below shows an example of the project file contents and folder structure within Visual Studio Code.

As you can see from the above screenshot, the .NET 8 Console App loaded within Visual Studio Code has a project (csproj) file that is in XML format and is required to run the program. Additionally, there are other artefacts such as the ‘bin’ and ‘obj’ folders that contain build and debug files, adding further noise.
What if we didn’t need any of these extra things and could just start with a single C# file and nothing else?
Enter Run File…
With the advent of .NET 10, things are being taken a step further. It is now possible to run a C# program with a single .cs file – no project file or anything else aside from the .NET SDK is needed!
With the new ‘Run File’ feature, a C# ‘project’ can be as simple as what is shown in the screenshot below.

Yes, that’s it, just a single .cs file within a folder. No project file or other artefacts are needed or appear within the working directory at any time, even after running the program.
Trying it out
If you’d like to try this out yourself, I recommend installing the latest version of Visual Studio Code.
To get the best tooling support and intellisense, etc., I also recommend that you install the Pre-Release version of the following Visual Studio Code Extensions.
Lastly, you will need to install the latest .NET 10 Preview SDK to support running single-file programs.
If you want to install the SDK very quickly, you can launch the Terminal within Visual Studio Code (View –> Terminal) and then run the following PowerShell command.
This command will download the ‘dotnet-install.ps1’ PowerShell script from the .NET website and execute it, installing the latest version of .NET 10 without leaving any residual files behind.
Now that you have the tooling in place, all you need to do is open an empty folder within Visual Studio Code and create a .cs file within it (e.g. ‘App.cs’) and then add some C# code into it (e.g. Console.WriteLine("Hello, World!");
).
Following this, launch the Terminal in Visual Studio Code (View –> Terminal) and then run the following command.
Note that you should change ‘App.cs’ according to what you have named your .cs file.
After running the dotnet run
command, you should see the output from your program appear within the Terminal window.
NuGet packages
NuGet packages are a major part of .NET development, and you may be wondering how we can use NuGet packages in single-file C# programs if there is no project file.
The good news is that it is indeed possible to use NuGet packages with this new approach, and it is straightforward to include them. Here’s a simple example that uses the Pastel NuGet package to output text to the Console in a specific colour.
Similar to preprocessor directives, such as #if
, the #:package
directive can signal to the compiler that some special processing needs to be done. In this case, including the specified NuGet package.
Note that you can include a particular version of a package by specifying the @
symbol after the package name e.g. to include the latest version 6 package, you could do this: #:package Pastel@6.*
You will likely notice that it takes a few seconds to run the program the first time when including one or more NuGet packages, as the package(s) will need to be restored before the program can compile and run. However, subsequent runs will typically be faster, and the .NET team is actively working to improve the performance of running C# programs in this new way.
Project conversion
So, what happens if we’ve created a program using this new approach and we decide that we want to take things further and convert it into a fully-fledged C# project?
This can be easily achieved by executing the following command.
The result of this command will be the creation of a csproj file with NuGet packages and any other properties transferred across from the original .cs file, as shown in the screenshot below.

It’s pretty nice that Microsoft have taken the time up front to think about making the conversion from the single-file to a full project as straightforward as possible.
Web Applications
There’s one last thing to cover before wrapping things up: let’s talk briefly about Web Apps and APIs.
One of the best things about .NET development is ASP.NET Core, a powerful and highly performant web development framework that is a key part of the .NET ecosystem and is a very popular option for developing both rich web applications for users, as well as APIs and other services.
It would be pretty cool if we could create a single-file API to mock something up, wouldn’t it?
Well, it turns out we can do this too with a minimal amount of code, as shown below.
The key part of the above code is the inclusion of the .NET Web SDK using the #:sdk
directive. The WebApplication
class can then be used as usual to create the builder that builds the app instance and subsequently runs the app, with a GET endpoint mapped to the root of the site for demonstration purposes.
The screenshot below shows the API running via the Terminal in Visual Studio Code.

If you do the same as above and point your browser at http://localhost:5000 (assuming your port number etc. is the same), you should find the text “Hello, World!” displayed on the webpage that loads.
Summary
In this article, I presented a brief history of how to create the simplest possible C# program across .NET versions, showing how this has been streamlined over the past few years, culminating in the capability of running a C# program without a project and nothing more than a single .cs file.
Following this, I listed the prerequisites for trying out the new ‘Run File’ approach for yourself and showed how you can include NuGet packages, even though there is no project file to reference them.
Lastly, I demonstrated how to convert a single-file C# program into a fully-fledged project and how to run Web Apps and APIs by referencing the .NET Web SDK.
I think the new Run File feature is a great addition to .NET! It will help to remove barriers and make C# an even more attractive option for both new and seasoned software developers alike.
Comments