C# Moves to Scripting

24 May 2025 5 min See Original (spanish)

The recent Build 2025 event took place and, although I don't usually cover it since there's rarely C#-specific programming news, it did leave us with a few gems, one of which we'll discuss in this post. We'll look at how the way we prototype applications in C# has changed, since compiling is no longer necessary.

 

 

NOTE: This feature is available in .NET 10 with C# 14, currently in preview. 

 

1 - Launch of C# as a scripting language in .NET 10

 

While it's true they haven't technically announced it like this, I believe it's clear they want to make C# a language that works for everyone and everything. So, in this new version, we can run C# code in the CLI without needing a project (.csproj), just a .cs file is more than enough. 

 

To do this, we create a file called test.cs and add the following line:

Console.WriteLine("hello world");

As you can see, it's a classic hello world, but the difference is there's no .csproj.

 

And in the terminal, we simply run the command dotnet run test.cs, and you'll see that it works perfectly: 

dotnet run file example español

What's happening behind the scenes is that the dotnet run command creates an msbuild project in a cache folder, restores the packages, compiles in the background, and runs the resulting binary. 

 

 

2 - Using SDKs and libraries

 

The idea behind these files is they offer full support for C#, including importing any library you want to use with the #:package instruction. If you want to go further and use an SDK (like the web SDK for minimal APIs), you can also do that with the #:sdk instruction. Here we can see an example:

 

#:sdk Microsoft.NET.Sdk.Web


var app = WebApplication.Create(args);
app.MapGet("/", () => "example minimal API");
app.Run();

 

If you run this example with dotnet run test.cs, it will launch a minimal API just like when you create a project from scratch.

dotnet run with api

 

3 - What is Microsoft aiming for with this change?

 

Personally, I've been saying for years that Microsoft is trying to attract talent from outside the .NET ecosystem to .NET itself. Years ago, we had top level statements, which allowed us to remove a lot of unnecessary code and indentation. Later, minimal APIs were introduced to reduce code for small projects and make C# feel more like other popular languages.

 

Now, they've finally taken the step to make C# a scripting language. I think that if it works out, it will (in the long term, of course) kill PowerShell, because there are so many .NET developers who, when they have to write a script, do it in another language like Python, since .NET wasn't convenient for it. Now, that's changing.

 

Moreover, this change makes adopting .NET and C# much easier for less experienced people, because the barrier to entry isn't as high, one file, one command, and you're ready to start practicing. 

 

Personally, I like the change, in fact, I love it, because I always have an empty test project I use to try things out. Now, I can just make a file and that's it.

 

Even so, it still needs polishing; I don't know if it will be released for .NET 10, but they absolutely need to integrate IntelliSense in Visual Studio Code and make it work perfectly for this feature to succeed. 

 

This post was translated from Spanish. You can see the original one here.
If there is any problem you can add a comment bellow or contact me in the website's contact form

Uso del bloqueador de anuncios adblock

Hola!

Primero de todo bienvenido a la web de NetMentor donde podrás aprender programación en C# y .NET desde un nivel de principiante hasta más avanzado.


Yo entiendo que utilices un bloqueador de anuncios como AdBlock, Ublock o el propio navegador Brave. Pero te tengo que pedir por favor que desactives el bloqueador para esta web.


Intento personalmente no poner mucha publicidad, la justa para pagar el servidor y por supuesto que no sea intrusiva; Si pese a ello piensas que es intrusiva siempre me puedes escribir por privado o por Twitter a @NetMentorTW.


Si ya lo has desactivado, por favor recarga la página.


Un saludo y muchas gracias por tu colaboración

© copyright 2025 NetMentor | Todos los derechos reservados | RSS Feed

Buy me a coffee Invitame a un café