`dotnet-exec` is a command-line tool for excuting C# program with custom entry point
dotnet-exec is a command-line tool for executing C# program without a project file, and you can have your custom entry point other than the Main method
Slides:
Github Action for executing without dotnet environment
Latest stable version:
dotnet tool update -g dotnet-executeLatest preview version:
dotnet tool update -g dotnet-execute --prereleaseInstall failed? try the command below:
dotnet tool update -g dotnet-execute --source https://api.nuget.org/v3/index.jsonor
dotnet tool update -g dotnet-execute --prerelease --add-source https://api.nuget.org/v3/index.json --ignore-failed-sourcesUninstall or failed to update? Try uninstall and install again
dotnet tool uninstall -g dotnet-executeExecute with docker
docker run --rm weihanli/dotnet-exec:latest "1+1"docker run --rm weihanli/dotnet-exec:latest "Guid.NewGuid()"docker run --rm --pull=always weihanli/dotnet-exec:latest "ApplicationHelper.RuntimeInfo"Execute with podman
podman run --rm weihanli/dotnet-exec:latest "1+1"podman run --rm weihanli/dotnet-exec:latest "Guid.NewGuid()"podman run --rm --pull=always weihanli/dotnet-exec:latest "ApplicationHelper.RuntimeInfo"for the full image tag list, see https://hub.docker.com/r/weihanli/dotnet-exec/tags
Execute local file:
dotnet-exec HttpPathJsonSample.csExecute a 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 the raw script:
dotnet-exec '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,3.0.0" -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,3.0.0" -u WeihanLi.NpoiExecute with additional dependencies
dotnet-exec 'typeof(LocalType).FullName.Dump();' FileLocalType2.csor with explicit addition references
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(features requires enable preview feature flag):
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'The alias command allows you to manage aliases for frequently used commands.
To list all configured aliases, use the list subcommand:
dotnet-exec alias listYou can also use dotnet-exec alias ls to list aliases.
To set a new alias, use the set subcommand followed by the alias name and value:
dotnet-exec alias set <aliasName> <aliasValue>For example, to set an alias for generating a new GUID:
dotnet-exec alias set guid "Guid.NewGuid()"use example:
dotnet-exec guidTo remove an existing alias, use the unset subcommand followed by the alias name:
dotnet-exec alias unset <aliasName>For example, to remove the guid alias:
dotnet-exec alias unset guid