dotnet-execute 0.19.0

dotnet tool install --global dotnet-execute --version 0.19.0
This package contains a .NET tool you can call from the shell/command line.
dotnet new tool-manifest # if you are setting up this repo
dotnet tool install --local dotnet-execute --version 0.19.0
This package contains a .NET tool you can call from the shell/command line.
#tool dotnet:?package=dotnet-execute&version=0.19.0
nuke :add-package dotnet-execute --version 0.19.0

dotnet-exec

Package Latest Latest Preview
dotnet-execute dotnet-execute dotnet-execute Latest
ReferenceResolver ReferenceResolver ReferenceResolver Latest

default

Docker Pulls

BuiltWithDot.Net shield

中文介绍

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:

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'

image

Executing with specific profile config and remove preset specific using:

dotnet-exec 'WebApplication.Create().Run();' --profile web --using '-WeihanLi.Extensions'

Acknowledgements

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

Version Downloads Last updated
0.19.0 230 4/21/2024
0.19.0-preview-20240421-150257 73 4/21/2024
0.19.0-preview-20240418-124656 64 4/18/2024
0.19.0-preview-20240414-090727 303 4/14/2024
0.19.0-preview-20240325-125324 431 3/25/2024
0.19.0-preview-20240313-155620 440 3/13/2024
0.19.0-preview-20240302-202752 730 3/2/2024
0.18.1 2,379 3/2/2024
0.18.0 629 3/1/2024
0.18.0-preview-20240229-183143 664 2/29/2024
0.18.0-preview-20240229-171025 638 2/29/2024
0.18.0-preview-20240229-170010 510 2/29/2024
0.18.0-preview-20240229-133804 570 2/29/2024
0.18.0-preview-20240225-075052 596 2/25/2024
0.18.0-preview-20240218-125959 606 2/18/2024
0.17.0 1,022 2/6/2024
0.17.0-preview-20240206-052156 608 2/6/2024
0.17.0-preview-20240201-150911 751 2/1/2024
0.17.0-preview-20240127-065141 1,074 1/27/2024
0.17.0-preview-20240117-161410 796 1/17/2024
0.16.0 1,332 1/5/2024
0.16.0-preview-20240105-112404 1,275 1/5/2024
0.16.0-preview-20240105-111327 1,099 1/5/2024
0.16.0-preview-20240104-161712 981 1/4/2024
0.16.0-preview-20240104-064502 1,025 1/4/2024
0.16.0-preview-20240103-183808 945 1/3/2024
0.16.0-preview-20240102-132944 1,198 1/2/2024
0.16.0-preview-20240101-163843 1,158 1/1/2024
0.16.0-preview-20231230-064352 1,097 12/30/2023
0.16.0-preview-20231230-045759 991 12/30/2023
0.16.0-preview-20231230-043451 1,183 12/30/2023
0.16.0-preview-20231230-040947 1,250 12/30/2023
0.16.0-preview-20231229-151551 1,192 12/29/2023
0.16.0-preview-20231227-032350 1,014 12/27/2023
0.15.0 1,436 11/23/2023
0.15.0-preview-20231123-133547 1,208 11/23/2023
0.15.0-preview-20231123-123533 1,306 11/23/2023
0.15.0-preview-20231123-113815 1,310 11/23/2023
0.15.0-preview-20231122-010942 1,421 11/22/2023
0.15.0-preview-20231112-135031 1,233 11/12/2023
0.15.0-preview-20231105-060850 1,174 11/5/2023
0.15.0-preview-20231011-155919 1,413 10/11/2023
0.15.0-preview-20230920-150633 1,489 9/20/2023
0.15.0-preview-20230916-043614 1,680 9/16/2023
0.15.0-preview-20230827-040803 1,677 8/27/2023
0.15.0-preview-20230715-072914 1,862 7/15/2023
0.15.0-preview-20230614-132940 1,612 6/14/2023
0.15.0-preview-20230517-162215 1,728 5/17/2023
0.14.0 1,974 4/22/2023
0.14.0-preview-20230419-153939 1,895 4/19/2023
0.14.0-preview-20230418-162203 1,710 4/18/2023
0.14.0-preview-20230415-012305 1,778 4/15/2023
0.14.0-preview-20230414-123704 1,698 4/14/2023
0.14.0-preview-20230412-140151 1,876 4/12/2023
0.14.0-preview-20230402-061327 2,098 4/2/2023
0.14.0-preview-20230327-163300 1,923 3/27/2023
0.14.0-preview-20230327-160902 1,876 3/27/2023
0.13.0 1,864 3/16/2023
0.13.0-preview-20230315-162605 1,817 3/15/2023
0.13.0-preview-20230226-133827 1,592 2/26/2023
0.13.0-preview-20230222-162344 1,804 2/22/2023
0.12.0 2,007 12/3/2022
0.12.0-preview-20221203-104240 1,639 12/3/2022
0.12.0-preview-20221203-071257 1,886 12/3/2022
0.12.0-preview-20221203-022812 1,799 12/3/2022
0.12.0-preview-20221202-163150 1,732 12/2/2022
0.12.0-preview-20221130-165115 1,731 11/30/2022
0.12.0-preview-20221130-004835 1,716 11/30/2022
0.12.0-preview-20221130-004015 1,826 11/30/2022
0.12.0-preview-20221129-162650 1,777 11/29/2022
0.12.0-preview-20221129-154228 1,806 11/29/2022
0.12.0-preview-20221129-152839 1,697 11/29/2022
0.12.0-preview-20221129-151920 1,659 11/29/2022
0.12.0-preview-20221126-142415 1,731 11/26/2022
0.12.0-preview-20221126-084550 1,593 11/26/2022
0.12.0-preview-20221126-081432 1,664 11/26/2022
0.12.0-preview-20221126-032548 1,676 11/26/2022
0.12.0-preview-20221125-161857 1,695 11/25/2022
0.11.0 1,892 11/22/2022
0.11.0-preview-20221121-153206 1,595 11/21/2022
0.11.0-preview-20221120-151824 1,835 11/20/2022
0.11.0-preview-20221120-142840 1,771 11/20/2022
0.11.0-preview-20221120-032905 1,861 11/20/2022
0.10.0 1,850 11/15/2022
0.10.0-preview-20221110-171942 1,639 11/10/2022
0.9.0 1,820 11/9/2022
0.9.0-preview-20221108-155221 1,852 11/8/2022
0.9.0-preview-20221108-154122 1,929 11/8/2022
0.9.0-preview-20221108-150547 1,711 11/8/2022
0.9.0-preview-20221101-123718 1,969 11/1/2022
0.9.0-preview-20221101-005949 1,807 11/1/2022
0.9.0-preview-20221031-145931 1,896 10/31/2022
0.9.0-preview-20221031-143055 1,977 10/31/2022
0.9.0-preview-20221031-134022 1,853 10/31/2022
0.9.0-preview-20221028-150337 1,833 10/28/2022
0.8.0 1,995 10/26/2022
0.8.0-preview-20221026-123049 1,816 10/26/2022
0.8.0-preview-20221016-120205 1,902 10/16/2022
0.8.0-preview-20220926-131419 2,083 9/26/2022
0.8.0-preview-20220919-153952 1,876 9/19/2022
0.8.0-preview-20220917-130443 1,899 9/17/2022
0.8.0-preview-20220915-133117 1,900 9/15/2022
0.8.0-preview-20220812-154602 1,655 8/12/2022
0.8.0-preview-20220727-000453 1,608 7/27/2022
0.7.0 2,127 7/17/2022
0.7.0-preview-20220717-115727 1,663 7/17/2022
0.7.0-preview-20220717-101132 1,793 7/17/2022
0.7.0-preview-20220717-084614 1,807 7/17/2022
0.7.0-preview-20220703-012835 1,843 7/3/2022
0.7.0-preview-20220702-093315 1,739 7/2/2022
0.7.0-preview-20220702-090636 1,995 7/2/2022
0.7.0-preview-20220702-073801 1,986 7/2/2022
0.7.0-preview-20220702-071552 1,782 7/2/2022
0.6.0 2,220 7/1/2022
0.6.0-preview-20220701-143726 1,814 7/1/2022
0.5.0 2,162 6/26/2022
0.5.0-preview-20220626-092804 1,956 6/26/2022
0.5.0-preview-20220626-081644 1,750 6/26/2022
0.4.0 2,150 6/18/2022
0.4.0-preview-20220616-164516 1,949 6/16/2022
0.4.0-preview-20220614-045540 2,014 6/14/2022
0.4.0-preview-20220612-155832 2,026 6/12/2022
0.4.0-preview-20220611-152348 2,408 6/11/2022
0.4.0-preview-20220611-021759 2,224 6/11/2022
0.4.0-preview-20220611-015329 2,258 6/11/2022
0.3.0 2,573 6/5/2022
0.3.0-preview-20220605-124120 2,357 6/5/2022
0.3.0-preview-20220605-122629 2,084 6/5/2022
0.3.0-preview-20220605-112734 2,318 6/5/2022
0.2.0 2,319 5/29/2022
0.2.0-preview-20220529-042432 2,080 5/29/2022
0.2.0-preview-20220525-151739 1,900 5/25/2022
0.2.0-preview-20220523-162548 2,049 5/23/2022
0.2.0-preview-20220523-151902 2,123 5/23/2022
0.2.0-preview-20220523-002551 2,134 5/23/2022
0.2.0-preview-20220522-165239 2,360 5/22/2022
0.2.0-preview-20220522-145024 2,154 5/22/2022
0.2.0-preview-20220518-154317 3,786 5/18/2022
0.2.0-preview-20220517-164722 4,040 5/17/2022
0.2.0-preview-20220517-162037 4,062 5/17/2022
0.1.1 4,657 5/4/2022
0.1.1-preview-20220504-152218 3,993 5/4/2022
0.1.0 2,517 5/4/2022
0.1.0-preview-20220504-072339 2,441 5/4/2022
0.1.0-preview-20220504-050757 2,455 5/4/2022
0.1.0-preview-20220503-161347 2,370 5/3/2022