`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.csExecute file with preview features:
dotnet-exec RawStringLiteral.cs --previewExecute 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"Execute raw code with custom reference:
dotnet-exec 'code:CsvHelper.GetCsvText(new[]{1,2,3}).Dump();' -r "nuget:WeihanLi.Npoi,2.3.0" --using "WeihanLi.Npoi"Execute script:
dotnet-exec 'script:1+1'Execute script with custom reference:
dotnet-exec 'script:Console.WriteLine(CsvHelper.GetCsvText(new[]{1,2,3}))' -r "nuget:WeihanLi.Npoi,2.3.0" -u WeihanLi.NpoiExecute raw code with docker
docker run --rm weihanli/dotnet-exec:latest dotnet-exec "code:(1+1).Dump()"By default, it's using the latest language version, you can use the Preview version with --preview/--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