menu
techminis

A naukri.com initiative

google-web-stories
Home

>

Programming News

>

Tutorial: ...
source image

Dev

1M

read

120

img
dot

Image Credit: Dev

Tutorial: Running Your C# Code Without a Project File

  • The tutorial explains how to run C# code without a project file using the .NET 10 Preview SDK.
  • This approach is helpful for quick tests, learning, and simple scripts without a full project structure.
  • Using dotnet run file.cs, you can directly compile and run C# programs without a .csproj setup.
  • You start by creating a C# source file named app.cs with basic code like printing to the console.
  • The CLI implicitly creates a project definition based on the default dotnet new console template to compile and run the file.
  • You can reference NuGet packages directly within the source file using app directives like #:package.
  • Advanced options include specifying SDK, properties, and using directives for finer control.
  • On Unix-like systems, you can make C# files executable like shell scripts using a shebang line.
  • The file-based execution model in .NET 10 Preview is recommended for simplicity and quick tasks, not for complex applications.
  • To transition to a full project structure, you can use dotnet project convert app.cs.

Read Full Article

like

7 Likes

For uninterrupted reading, download the app