{"id":530,"date":"2025-05-30T08:05:28","date_gmt":"2025-05-30T11:05:28","guid":{"rendered":"https:\/\/rodrigoduclerc.net\/site\/en\/?p=530"},"modified":"2025-05-30T11:35:48","modified_gmt":"2025-05-30T14:35:48","slug":"microsoft-introduces-direct-c-file-execution-in-net-10-preview-4","status":"publish","type":"post","link":"https:\/\/rodrigoduclerc.net\/site\/en\/2025\/05\/30\/microsoft-introduces-direct-c-file-execution-in-net-10-preview-4\/","title":{"rendered":"Microsoft Introduces Direct C# File Execution in .NET 10 Preview 4"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Microsoft Introduces Direct C# File Execution in .NET 10 Preview 4<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Microsoft has unveiled an exciting new capability in .NET 10 Preview 4 that fundamentally changes how developers can work with C#. The new <code>dotnet run app.cs<\/code> command allows developers to execute C# files directly, eliminating the traditional requirement for project files and complex scaffolding.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Breaking Down Barriers to Entry<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Historically, running C# code required creating a complete project structure with <code>.csproj<\/code> files, which could be intimidating for beginners or cumbersome for quick experiments. This new feature, dubbed &#8220;file-based apps,&#8221; transforms C# into a more approachable language that competes directly with scripting languages like Python and JavaScript.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Powerful New Directives<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The feature introduces several file-level directives that bring project-like capabilities to standalone files:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>#:package<\/code><\/strong> &#8211; Add NuGet package references directly in your .cs file<\/li>\n\n\n\n<li><strong><code>#:sdk<\/code><\/strong> &#8211; Specify different SDKs (perfect for web applications using ASP.NET Core)<\/li>\n\n\n\n<li><strong><code>#:property<\/code><\/strong> &#8211; Configure MSBuild properties for advanced language features<\/li>\n\n\n\n<li><strong>Shebang support<\/strong> &#8211; Create executable C# shell scripts on Unix-like systems<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Seamless Growth Path<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Perhaps most importantly, this isn&#8217;t a separate runtime or dialect. When your simple script grows into a complex application, the <code>dotnet project convert app.cs<\/code> command automatically transforms it into a full project structure, preserving all your code and translating directives into proper MSBuild configurations.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Community Reception<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The developer community has responded enthusiastically, particularly praising its potential for education and rapid prototyping. While some developers have requested additional features like REPL functionality and double-click execution, Microsoft has indicated that security considerations will guide future enhancements.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Getting Started<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">To try this feature, developers need to install .NET 10 Preview 4 and optionally use Visual Studio Code with the C# Dev Kit extension. The feature works immediately with any <code>.cs<\/code> file, making it as simple as creating a file and running <code>dotnet run filename.cs<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This development represents Microsoft&#8217;s commitment to making C# more accessible while preserving the power and sophistication that makes .NET a enterprise-grade platform.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Source: <a href=\"https:\/\/devblogs.microsoft.com\/dotnet\/announcing-dotnet-run-app\/\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/devblogs.microsoft.com\/dotnet\/announcing-dotnet-run-app\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Microsoft has revolutionized C# development with the introduction of dotnet run app.cs in .NET 10 Preview 4, allowing developers to execute C# files directly without creating project structures. This game-changing feature makes C# as accessible as Python or JavaScript for scripting, learning, and rapid prototyping while maintaining full compatibility with the .NET ecosystem.<\/p>\n","protected":false},"author":1,"featured_media":541,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[73],"tags":[],"class_list":["post-530","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tech-news"],"_links":{"self":[{"href":"https:\/\/rodrigoduclerc.net\/site\/en\/wp-json\/wp\/v2\/posts\/530","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/rodrigoduclerc.net\/site\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/rodrigoduclerc.net\/site\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/rodrigoduclerc.net\/site\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/rodrigoduclerc.net\/site\/en\/wp-json\/wp\/v2\/comments?post=530"}],"version-history":[{"count":10,"href":"https:\/\/rodrigoduclerc.net\/site\/en\/wp-json\/wp\/v2\/posts\/530\/revisions"}],"predecessor-version":[{"id":555,"href":"https:\/\/rodrigoduclerc.net\/site\/en\/wp-json\/wp\/v2\/posts\/530\/revisions\/555"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/rodrigoduclerc.net\/site\/en\/wp-json\/wp\/v2\/media\/541"}],"wp:attachment":[{"href":"https:\/\/rodrigoduclerc.net\/site\/en\/wp-json\/wp\/v2\/media?parent=530"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rodrigoduclerc.net\/site\/en\/wp-json\/wp\/v2\/categories?post=530"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rodrigoduclerc.net\/site\/en\/wp-json\/wp\/v2\/tags?post=530"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}