Story Details

  • Run a C# file directly using dotnet run app.cs

    Posted: 2025-05-29 02:30:28

    The dotnet run command now supports directly executing single C# files, simplifying the process of running small programs or scripts. Previously, creating a project file was necessary, adding overhead for simple tasks. This streamlined approach allows developers to run dotnet run myapp.cs directly, handling compilation and execution in one step. The feature supports top-level statements, NuGet package dependencies declared within the file using #nullable directives, preprocessor directives, and more, providing a convenient and powerful way to execute C# code without project file management. This enhances the scripting capabilities of C# and makes it easier for quick prototyping and experimentation.

    Summary of Comments ( 202 )
    https://news.ycombinator.com/item?id=44122582

    HN commenters generally express enthusiasm for dotnet run app.cs, finding it a welcome simplification for running single-file C# programs. Several compare it favorably to similar functionality in other languages like Python, Ruby, and JavaScript, appreciating the reduced ceremony for quick scripts and experimentation. Some raise questions about how it handles dependencies and more complex projects, while others note potential implications for teaching and onboarding new C# developers. A few point out that this feature isn't entirely new, with similar results achievable through piping to the compiler, but acknowledge the improved developer experience this dedicated command offers. There's also discussion about compilation speed and whether pre-compilation might offer further performance improvements for repeated executions.