How to install dotnet script
dotnet script
enables you to run C# scripts (.CSX
) from the .NET CLI. The only requirement is to have .NET 6 or newer installed on your machine.
You can use the following command to install dotnet-script globally:
dotnet tool install -g dotnet-script
Code language: Bash (bash)
Then to execute a script file you simply call dotnet script <file_path>
like in the example below:
dotnet script startdebugging.csx
Code language: Bash (bash)
How to initialize a new dotnet script
If you are just getting started and you want to create a new dotnet script file you can use the init
command to scaffold a script project.
dotnet script init startdebugging.csx
Code language: Bash (bash)
This will create your script file along with the launch configuration needed to debug the script using VS Code. Note that the file name is optional and will default to main.csx
if you don’t specify it.
.
├── .vscode
│ └── launch.json
├── startdebugging.csx
└── omnisharp.json
Code language: plaintext (plaintext)
Implicit usings
dotnet script comes with some namespaces included by default, similar to the implicit usings feature you’re used with in .NET SDK projects. Below you have the full list of namespaces implicitly available in dotnet-script.
System
System.IO
System.Collections.Generic
System.Console
System.Diagnostics
System.Dynamic
System.Linq
System.Linq.Expressions
System.Text
System.Threading.Tasks
Code language: C# (cs)