`dotnet-exec` is a command-line tool for excuting C# program with custom entry point
$ dotnet add package dotnet-executedotnet-exec is a command line tool for executing C# program without a project file, and you can have your custom entry point other than Main method
Latest stable version:
dotnet tool update -g dotnet-execute
Latest preview version:
dotnet tool update -g dotnet-execute --prerelease
Execute local file:
dotnet-exec HttpPathJsonSample.cs
Execute local file with custom entry point:
dotnet-exec HttpPathJsonSample.cs --entry MainTest
Execute remote file:
dotnet-exec https://github.com/WeihanLi/SamplesInPractice/blob/master/net7Sample/Net7Sample/ArgumentExceptionSample.cs
Execute file with preview features:
dotnet-exec RawStringLiteral.cs --preview
Execute raw code:
dotnet-exec 'code:Console.WriteLine(1+1);'
Execute raw code with custom usings:
dotnet-exec 'code:WriteLine(1+1);' --using "static System.Console"By default, it's using the latest language version, you can use the Preview version with --lang-version=Preview
By default, it would use MainTest as the entry point, you can customize with --entry option
By default, it would use net7.0 if you've installed .NET 7 SDK, otherwise use .NET 6 instead, you can customize with the -f/--framework option
By default, it would use the SimpleCodeCompiler to compile the code, you can customize with the --compiler-type option, and you can use -a/--advanced for --compiler-type=advanced