Revolutionize Your Workflow with .NET 10's New Script Mode

Run C# Without a Project in .NET 10 Preview 4

What if you could run a C# file instantly without the hassle of creating a full project? With .NET 10 Preview 4, that’s no longer a what-if. This game-changing update introduces a lightweight scripting model that makes C# feel as snappy as Python or JavaScript.

Simply write your code in a .cs file, then execute it with:

dotnet run myScript.cs

No .csproj file. No boilerplate. Just pure C# logic.

This is perfect for:

  • Quick prototyping
  • Writing automation scripts
  • Exploring new APIs
  • Teaching and learning C# without setup overhead

But it gets better. You can now include metadata in your script with powerful directives:

#:package Humanizer@2.14.1
using Humanizer;

Console.WriteLine($"It’s {DateTimeOffset.Now.Humanize()}!");

This pulls in the Humanizer NuGet package, directly from your script. No need to manually restore packages or edit a project file.

Need a specific SDK or language version? Use:

#:sdk Microsoft.NET.Sdk.Web
#:property LangVersion preview

These directives guide the compiler and project converter, ensuring your script aligns with your runtime and feature needs.

Even Unix-style shebangs are supported:

#!/usr/bin/env dotnet run

This makes your scripts directly executable on Linux/macOS systems with executable permissions set.

And when your script matures beyond a few lines? Run this to upgrade:

dotnet project convert myScript.cs

This command scaffolds a proper .NET project using the directives in your script as a blueprint.

Tooling support is already solid. In VS Code, just open the .cs file and hit F5. While full IntelliSense is still evolving, you get basic code navigation, syntax checking, and integrated terminal execution.

Sure, there’s a small compile step on first run, so it’s not as instantaneous as an interpreted script. But the trade-off is well worth it for type safety, refactorability, and full .NET power.

Ready to ditch the ceremony and dive straight into code? .NET 10’s script mode is your new best friend.

What will you build first with this new capability? Drop your script ideas in the comments below!

Leave a Reply

Your email address will not be published. Required fields are marked *