.NET 10 brings βdotnet run app.csβ
Finally! We are super excited to announce that Microsoft have implemented a long-awaited feature that will transform your experience of C# scripts using just the dotnet run
command! This is a feature that is released with the fourth preview of .NET 10.
It was ages ago since weβve announced anything exciting, because weβre in an era where the majority of developments are in artifical intelligence (AI).
You can now get started with C# easier than before. Using just a C# code file and a dotnet command, you can run simple programs! This is to streamline the experience with C#, especially if youβre just getting started. File-based apps feature is inspired by JavaScript (.js), Python (.py), and other scripting languages. File-based apps are also scalable, ensuring that you can make real and complex applications using just the C# files.
New directives have been introduced to the file-based C# scripts that allow you to declare a small number of important properties, such as NuGet packages (#:package Terminaux@7.0.0
), SDK specifications (#:sdk Microsoft.NET.Sdk.Web
), and MSBuild properties (#:property LangVersion Preview
). This is to achieve maximum flexibility, since you can make very complex applications with lots of dependencies using just a single C# file.
The most exciting part is that you can now run a C# file as if it were a Bash script (.sh, .bash, and so on) in Unix systems! Using just a shebang at the top of the file (#!/usr/bin/dotnet run
), you can finally make executable C# scripts using just the name of the source code file. To do this, set the executable bit using the chmod
command.
$ chmod +x app.cs$ ./app.cs
This is a great feature for anyone who are making applications and/or small scripts without making a C# project file. However, you can convert it to the standard project-based application, should the C# scripts file become too complex to handle.
You can read more about this feature by clicking on the below button.
Learn more Image by diana.grytsku on Freepik
#csharp #dotnet #dotnetRun #dotnetRunApp #news #Programming #Tech #Technology #update