How to pass arguments to a dotnet script
When using dotnet script you can pass arguments by specifying them after — (two dashes). You can the access the arguments in the script using the Args collection.
Let’s take an example. Assume we have the following myScript.csx script file:
Console.WriteLine($"Inputs: {string.Join(", ", Args)}");
Code language: C# (cs)
We can pass parameter to this script as follows:
dotnet script myScript.csx -- "a" "b"
Code language: C# (cs)
even without — (two dashes), it works
PS > dotnet script .\first_script.csx “asdf” “sgdgsfdg”
Hello world!
Inputs: asdf, sgdgsfdg
PS > dotnet script .\first_script.csx — “asdf” “sgdgsfdg”
Hello world!
Inputs: asdf, sgdgsfdg