dotnet-execute
0.23.0-preview-20240815-002214
See the version list below for details.
dotnet tool install --global dotnet-execute --version 0.23.0-preview-20240815-002214
dotnet new tool-manifest # if you are setting up this repo dotnet tool install --local dotnet-execute --version 0.23.0-preview-20240815-002214
#tool dotnet:?package=dotnet-execute&version=0.23.0-preview-20240815-002214&prerelease
nuke :add-package dotnet-execute --version 0.23.0-preview-20240815-002214
dotnet-exec
Package | Latest | Latest Preview |
---|---|---|
dotnet-execute | ||
ReferenceResolver |
Intro
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:
- Makes C# more simple -- .NET Conf China 2022
- dotnet-exec simpler C# -- .NET Conf China 2023 Watch Party Shanghai
Github Action for executing without dotnet environment
Install/Update
dotnet tool
Latest stable version:
dotnet tool update -g dotnet-execute
Latest preview version:
dotnet tool update -g dotnet-execute --prerelease
Install failed? try the command below:
dotnet tool update -g dotnet-execute --prerelease --add-source https://api.nuget.org/v3/index.json --ignore-failed-sources
Container support
Execute 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
Examples
Get started
Execute local file:
dotnet-exec HttpPathJsonSample.cs
Execute a 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 raw code:
dotnet-exec 'Console.WriteLine(1+1);'
Execute the raw script:
dotnet-exec '1 + 1'
dotnet-exec 'Guid.NewGuid()'
References
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();' --web
Usings
Execute 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.Npoi
More
Execute with additional dependencies
dotnet-exec 'typeof(LocalType).FullName.Dump();' --ad FileLocalType2.cs
dotnet-exec 'typeof(LocalType).FullName.Dump();' --addition FileLocalType2.cs
Execute with exacting references and usings from the project file
dotnet-exec 'typeof(LocalType).FullName.Dump();' --project ./Sample.csproj
Execute file with preview features:
dotnet-exec RawStringLiteral.cs --preview
Config Profile
You can customize the config you used often into a config profile to reuse it for convenience.
List the profiles had configured:
dotnet-exec profile ls
Configure a profile:
dotnet-exec profile set web -r "nuget:WeihanLi.Web.Extensions" -u 'WeihanLi.Web.Extensions' --web --wide false
Get the profile details:
dotnet-exec profile get web
Remove the profile not needed:
dotnet-exec profile rm web
Executing 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'
Acknowledgements
- Roslyn
- NuGet.Clients
- System.CommandLine
- Thanks JetBrains for the open source Rider license
- Many thanks to the contributors and users for this project
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. |
This package has no dependencies.
Version | Downloads | Last updated |
---|---|---|
0.24.0 | 79 | 11/24/2024 |
0.24.0-preview-20241124-035720 | 55 | 11/24/2024 |
0.24.0-preview-20241117-021926 | 246 | 11/17/2024 |
0.24.0-preview-20241025-003522 | 424 | 10/25/2024 |
0.24.0-preview-20241010-163230 | 227 | 10/10/2024 |
0.24.0-preview-20241009-161812 | 250 | 10/9/2024 |
0.24.0-preview-20241009-152619 | 167 | 10/9/2024 |
0.24.0-preview-20241004-001036 | 330 | 10/4/2024 |
0.24.0-preview-20241003-015422 | 236 | 10/3/2024 |
0.24.0-preview-20241002-173926 | 198 | 10/2/2024 |
0.24.0-preview-20240918-153023 | 308 | 9/18/2024 |
0.24.0-preview-20240911-171636 | 218 | 9/11/2024 |
0.23.0 | 3,765 | 8/29/2024 |
0.23.0-preview-20240824-102835 | 198 | 8/24/2024 |
0.23.0-preview-20240815-002214 | 344 | 8/15/2024 |
0.22.0 | 2,009 | 7/10/2024 |
0.21.0 | 1,168 | 6/15/2024 |
0.20.0 | 562 | 6/6/2024 |
0.19.0 | 1,751 | 4/21/2024 |
0.18.1 | 2,517 | 3/2/2024 |
0.18.0 | 732 | 3/1/2024 |
0.17.0 | 1,098 | 2/6/2024 |
0.16.0 | 1,445 | 1/5/2024 |
0.15.0 | 1,512 | 11/23/2023 |
0.14.0 | 2,046 | 4/22/2023 |
0.13.0 | 1,934 | 3/16/2023 |
0.12.0 | 2,069 | 12/3/2022 |
0.11.0 | 1,955 | 11/22/2022 |
0.10.0 | 1,903 | 11/15/2022 |
0.9.0 | 1,868 | 11/9/2022 |
0.8.0 | 2,065 | 10/26/2022 |
0.7.0 | 2,176 | 7/17/2022 |
0.6.0 | 2,289 | 7/1/2022 |
0.5.0 | 2,214 | 6/26/2022 |
0.4.0 | 2,200 | 6/18/2022 |
0.3.0 | 2,658 | 6/5/2022 |
0.2.0 | 2,368 | 5/29/2022 |
0.1.1 | 4,762 | 5/4/2022 |
0.1.0 | 2,565 | 5/4/2022 |