Editor at Large

C# 14 introduces file-based apps

news
Jun 3, 20252 mins

New capability in .NET 10 Preview 4 allows developers to run a stand-alone C# file directly, without requiring a project file or project structure.

Image for: New capability in .NET 10 Preview 4 allows developers to run a stand-alone C# file directly, without

Credit: Tee11 / Shutterstock

Taking a lesson from scripting languages such as Python and JavaScript, Microsoft has introduced a file-based apps capability for the C# language, which is intended to streamline C# development.

Introduced in .NET 10 Preview 4, the new feature allows developers to run a stand-alone C# (.cs) file directly with the command, dotnet run app.cs. Developers no longer need to create a project file or scaffold an entire application to test a test snippet, run a quick script, or experiment with an idea, wrote Damian Edwards, principal architect at Microsoft, in a May 28 blog post announcing the feature. Previously, running C# code using the dotnet CLI has required a project structure that included a .csproj file. Developers can get started with the feature by downloading .NET 10 Preview 4.

File-based apps lower the entry barrier to trying out C# and make the language a more-attractive choice for learning, prototyping, and automation scenarios, Edwards said. Developers get a quick start while no project file is required, there is “first-class” CLI integration, and the capability scales to real applications. There is no separate dialect or runtime; when a script grows up, it can evolve into a full-fledged project using the same language, syntax, and tools. With .NET 10 Preview 4, file-based apps also support a set of file-level directives to declare packages, SDKs, and properties (which are stored in project files for project apps) without leaving a .cs file.

Microsoft with dotnet run app.cs believes it is making C# more approachable while preserving the power and depth of the .NET ecosystem. Upcoming .NET previews will aim to improve the experience of working with file-based apps in Visual Studio Code, with enhanced IntelliSense for new file-based directives, improved performance, and debugging support, Edwards said. For the command line, Microsoft is looking into support for file-based apps with multiple files and ways to make running file-based apps faster. Microsoft asks developers to try out the capability and send feedback to GitHub.

Paul Krill is editor at large at InfoWorld. Paul has been covering computer technology as a news and feature reporter for more than 35 years, including 30 years at InfoWorld. He has specialized in coverage of software development tools and technologies since the 1990s, and he continues to lead InfoWorld’s news coverage of software development platforms including Java and .NET and programming languages including JavaScript, TypeScript, PHP, Python, Ruby, Rust, and Go. Long trusted as a reporter who prioritizes accuracy, integrity, and the best interests of readers, Paul is sought out by technology companies and industry organizations who want to reach InfoWorld’s audience of software developers and other information technology professionals. Paul has won a “Best Technology News Coverage” award from IDG.

More from this author

Image for: More from this author