`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 with docker
docker run --rm weihanli/dotnet-exec:latest dotnet-exec "1+1"
docker run --rm weihanli/dotnet-exec:latest dotnet-exec "Guid.NewGuid()"
docker run --rm --pull=always weihanli/dotnet-exec:latest dotnet-exec "ApplicationHelper.RuntimeInfo"Execute with podman
podman run --rm weihanli/dotnet-exec:latest dotnet-exec "1+1"podman run --rm weihanli/dotnet-exec:latest dotnet-exec "Guid.NewGuid()"podman run --rm --pull=always weihanli/dotnet-exec:latest dotnet-exec "ApplicationHelper.RuntimeInfo"for full image tag list, see https://hub.docker.com/r/weihanli/dotnet-exec/tags
Execute local file:
dotnet-exec HttpPathJsonSample.csExecute local file with custom entry point:
dotnet-exec 'HttpPathJsonSample.cs' --entry MainTestExecute remote file:
dotnet-exec https://github.com/WeihanLi/SamplesInPractice/blob/master/net7Sample/Net7Sample/ArgumentExceptionSample.csExecute raw code:
dotnet-exec 'Console.WriteLine(1+1);'Execute raw script:
dotnet-exec 'script:1+1'dotnet-exec 'Guid.NewGuid()'Execute raw code with custom references:
NuGet package reference:
dotnet-exec 'CsvHelper.GetCsvText(new[]{1,2,3}).Dump();' -r "nuget: WeihanLi.Npoi,2.4.2" -u "WeihanLi.Npoi"Local dll reference:
dotnet-exec 'CsvHelper.GetCsvText(new[]{1,2,3}).Dump();' -r "./out/WeihanLi.Npoi.dll" -u "WeihanLi.Npoi"Local dll in a folder references:
dotnet-exec 'CsvHelper.GetCsvText(new[]{1,2,3}).Dump();' -r "folder: ./out" -u "WeihanLi.Npoi"Local project reference:
dotnet-exec 'CsvHelper.GetCsvText(new[]{1,2,3}).Dump();' -r "project: ./WeihanLi.Npoi.csproj" -u "WeihanLi.Npoi"Framework reference:
dotnet-exec 'WebApplication.Create().Run();' --reference 'framework:web'Web framework reference in one option:
dotnet-exec 'WebApplication.Create().Run();' --webExecute raw code with custom usings:
dotnet-exec 'WriteLine(1+1);' --using "static System.Console"Execute script with custom reference:
dotnet-exec 'CsvHelper.GetCsvText(new[]{1,2,3}).Dump()' -r "nuget:WeihanLi.Npoi,2.4.2" -u WeihanLi.NpoiExecute with additional dependencies
dotnet-exec 'typeof(LocalType).FullName.Dump();' --ad FileLocalType2.csdotnet-exec 'typeof(LocalType).FullName.Dump();' --addition FileLocalType2.csExecute with exacting references and usings from the project file
dotnet-exec 'typeof(LocalType).FullName.Dump();' --project ./Sample.csprojExecute file with preview features:
dotnet-exec RawStringLiteral.cs --previewYou can customize the config you used often into a config profile to reuse it for convenience.
List the profiles had configured:
dotnet-exec profile lsConfigure a profile:
dotnet-exec profile set web -r "nuget:WeihanLi.Web.Extensions" -u 'WeihanLi.Web.Extensions' --web --wide falseGet the profile details:
dotnet-exec profile get webRemove the profile not needed:
dotnet-exec profile rm webExecuting with specific profile config:
dotnet-exec 'WebApplication.Create().Chain(_=>_.MapRuntimeInfo()).Run();' --profile web --using 'WeihanLi.Extensions'
Executing with specific profile config and remove preset specific using:
dotnet-exec 'WebApplication.Create().Run();' --profile web --using '-WeihanLi.Extensions'