New in .NET 10.0 [13]: Compile and run single C# files

Since .NET 10.0, you can compile and run individual C# files directly – without needing a project file.

listen Print view
C#

(Image: Pincasso / Shutterstock.com)

1 min. read
By
  • Dr. Holger Schwichtenberg

For the direct translation and execution of C# files, Microsoft offers file-based apps. The prerequisite is that the .NET Software Development Kit (SDK) version 10.0 or higher is installed.

An installation of the .NET Runtime is not sufficient for this!

The Dotnet Doctor – Holger Schwichtenberg
Der Dotnet-Doktor – Holger Schwichtenberg

Dr. Holger Schwichtenberg is the technical director of the expert network www.IT-Visions.de, which supports numerous medium-sized and large companies with consulting and training services as well as software development, drawing on the expertise of 53 renowned experts. Thanks to his appearances at numerous national and international conferences, as well as more than 90 specialist books and over 1,500 specialist articles, Holger Schwichtenberg is one of the best-known experts for .NET and web technologies in Germany.

With this new feature, C# can also be used as a scripting language, for example, for scripts in development projects where PowerShell or bash was previously used. However, there were already approaches outside of Microsoft for this:

Videos by heise

C# scripting in the .NET 10.0 SDK is possible with the .NET SDK CLI command dotnet run:

dotnet run .ilename.cs

Alternatively, a C# file can also be executed directly without specifying the word run:

dotnet .ilename.cs

Executing a standalone C# file with dotnet run in the Visual Studio Code terminal (Fig. 1)

For input assistance and debugging in Visual Studio Code for File-based Apps, you should set the appropriate checkbox in the editor settings (Fig. 2).

(mack)

Don't miss any news – follow us on Facebook, LinkedIn or Mastodon.

This article was originally published in German. It was translated with technical assistance and editorially reviewed before publication.