dotnet-execute 0.17.0

There is a newer prerelease version of this package available.
See the version list below for details.
dotnet tool install --global dotnet-execute --version 0.17.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.17.0
This package contains a .NET tool you can call from the shell/command line.
#tool dotnet:?package=dotnet-execute&version=0.17.0
nuke :add-package dotnet-execute --version 0.17.0

dotnet-exec

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

default

Docker Pulls

中文介绍

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. 
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

Version Downloads Last updated
0.18.0-preview-20240218-125959 47 2/18/2024
0.17.0 252 2/6/2024
0.17.0-preview-20240206-052156 95 2/6/2024
0.17.0-preview-20240201-150911 229 2/1/2024
0.17.0-preview-20240127-065141 404 1/27/2024
0.17.0-preview-20240117-161410 352 1/17/2024
0.16.0 837 1/5/2024
0.16.0-preview-20240105-112404 587 1/5/2024
0.16.0-preview-20240105-111327 473 1/5/2024
0.16.0-preview-20240104-161712 459 1/4/2024
0.16.0-preview-20240104-064502 496 1/4/2024
0.16.0-preview-20240103-183808 463 1/3/2024
0.16.0-preview-20240102-132944 768 1/2/2024
0.16.0-preview-20240101-163843 598 1/1/2024
0.16.0-preview-20231230-064352 586 12/30/2023
0.16.0-preview-20231230-045759 507 12/30/2023
0.16.0-preview-20231230-043451 643 12/30/2023
0.16.0-preview-20231230-040947 547 12/30/2023
0.16.0-preview-20231229-151551 582 12/29/2023
0.16.0-preview-20231227-032350 538 12/27/2023
0.15.0 872 11/23/2023
0.15.0-preview-20231123-133547 619 11/23/2023
0.15.0-preview-20231123-123533 804 11/23/2023
0.15.0-preview-20231123-113815 654 11/23/2023
0.15.0-preview-20231122-010942 852 11/22/2023
0.15.0-preview-20231112-135031 766 11/12/2023
0.15.0-preview-20231105-060850 558 11/5/2023
0.15.0-preview-20231011-155919 905 10/11/2023
0.15.0-preview-20230920-150633 1,029 9/20/2023
0.15.0-preview-20230916-043614 1,020 9/16/2023
0.15.0-preview-20230827-040803 1,182 8/27/2023
0.15.0-preview-20230715-072914 1,306 7/15/2023
0.15.0-preview-20230614-132940 1,087 6/14/2023
0.15.0-preview-20230517-162215 1,302 5/17/2023
0.14.0 1,491 4/22/2023
0.14.0-preview-20230419-153939 1,313 4/19/2023
0.14.0-preview-20230418-162203 1,221 4/18/2023
0.14.0-preview-20230415-012305 1,212 4/15/2023
0.14.0-preview-20230414-123704 1,279 4/14/2023
0.14.0-preview-20230412-140151 1,316 4/12/2023
0.14.0-preview-20230402-061327 1,392 4/2/2023
0.14.0-preview-20230327-163300 1,317 3/27/2023
0.14.0-preview-20230327-160902 1,371 3/27/2023
0.13.0 1,521 3/16/2023
0.13.0-preview-20230315-162605 1,344 3/15/2023
0.13.0-preview-20230226-133827 1,142 2/26/2023
0.13.0-preview-20230222-162344 1,296 2/22/2023
0.12.0 1,564 12/3/2022
0.12.0-preview-20221203-104240 1,231 12/3/2022
0.12.0-preview-20221203-071257 1,342 12/3/2022
0.12.0-preview-20221203-022812 1,222 12/3/2022
0.12.0-preview-20221202-163150 1,100 12/2/2022
0.12.0-preview-20221130-165115 1,195 11/30/2022
0.12.0-preview-20221130-004835 1,212 11/30/2022
0.12.0-preview-20221130-004015 1,379 11/30/2022
0.12.0-preview-20221129-162650 1,305 11/29/2022
0.12.0-preview-20221129-154228 1,212 11/29/2022
0.12.0-preview-20221129-152839 1,201 11/29/2022
0.12.0-preview-20221129-151920 1,169 11/29/2022
0.12.0-preview-20221126-142415 1,190 11/26/2022
0.12.0-preview-20221126-084550 1,002 11/26/2022
0.12.0-preview-20221126-081432 1,224 11/26/2022
0.12.0-preview-20221126-032548 1,150 11/26/2022
0.12.0-preview-20221125-161857 1,237 11/25/2022
0.11.0 1,466 11/22/2022
0.11.0-preview-20221121-153206 1,022 11/21/2022
0.11.0-preview-20221120-151824 1,315 11/20/2022
0.11.0-preview-20221120-142840 1,230 11/20/2022
0.11.0-preview-20221120-032905 1,274 11/20/2022
0.10.0 1,459 11/15/2022
0.10.0-preview-20221110-171942 1,175 11/10/2022
0.9.0 1,366 11/9/2022
0.9.0-preview-20221108-155221 1,261 11/8/2022
0.9.0-preview-20221108-154122 1,378 11/8/2022
0.9.0-preview-20221108-150547 1,135 11/8/2022
0.9.0-preview-20221101-123718 1,319 11/1/2022
0.9.0-preview-20221101-005949 1,200 11/1/2022
0.9.0-preview-20221031-145931 1,190 10/31/2022
0.9.0-preview-20221031-143055 1,333 10/31/2022
0.9.0-preview-20221031-134022 1,312 10/31/2022
0.9.0-preview-20221028-150337 1,316 10/28/2022
0.8.0 1,522 10/26/2022
0.8.0-preview-20221026-123049 1,269 10/26/2022
0.8.0-preview-20221016-120205 1,256 10/16/2022
0.8.0-preview-20220926-131419 1,422 9/26/2022
0.8.0-preview-20220919-153952 1,322 9/19/2022
0.8.0-preview-20220917-130443 1,398 9/17/2022
0.8.0-preview-20220915-133117 1,337 9/15/2022
0.8.0-preview-20220812-154602 1,192 8/12/2022
0.8.0-preview-20220727-000453 1,117 7/27/2022
0.7.0 1,520 7/17/2022
0.7.0-preview-20220717-115727 1,205 7/17/2022
0.7.0-preview-20220717-101132 1,317 7/17/2022
0.7.0-preview-20220717-084614 1,186 7/17/2022
0.7.0-preview-20220703-012835 1,338 7/3/2022
0.7.0-preview-20220702-093315 1,125 7/2/2022
0.7.0-preview-20220702-090636 1,412 7/2/2022
0.7.0-preview-20220702-073801 1,367 7/2/2022
0.7.0-preview-20220702-071552 1,321 7/2/2022
0.6.0 1,653 7/1/2022
0.6.0-preview-20220701-143726 1,234 7/1/2022
0.5.0 1,495 6/26/2022
0.5.0-preview-20220626-092804 1,388 6/26/2022
0.5.0-preview-20220626-081644 1,195 6/26/2022
0.4.0 1,704 6/18/2022
0.4.0-preview-20220616-164516 1,366 6/16/2022
0.4.0-preview-20220614-045540 1,439 6/14/2022
0.4.0-preview-20220612-155832 1,521 6/12/2022
0.4.0-preview-20220611-152348 1,625 6/11/2022
0.4.0-preview-20220611-021759 1,664 6/11/2022
0.4.0-preview-20220611-015329 1,567 6/11/2022
0.3.0 1,868 6/5/2022
0.3.0-preview-20220605-124120 1,686 6/5/2022
0.3.0-preview-20220605-122629 1,593 6/5/2022
0.3.0-preview-20220605-112734 1,444 6/5/2022
0.2.0 1,695 5/29/2022
0.2.0-preview-20220529-042432 1,395 5/29/2022
0.2.0-preview-20220525-151739 1,302 5/25/2022
0.2.0-preview-20220523-162548 1,329 5/23/2022
0.2.0-preview-20220523-151902 1,393 5/23/2022
0.2.0-preview-20220523-002551 1,511 5/23/2022
0.2.0-preview-20220522-165239 1,602 5/22/2022
0.2.0-preview-20220522-145024 1,505 5/22/2022
0.2.0-preview-20220518-154317 2,659 5/18/2022
0.2.0-preview-20220517-164722 2,880 5/17/2022
0.2.0-preview-20220517-162037 2,570 5/17/2022
0.1.1 3,427 5/4/2022
0.1.1-preview-20220504-152218 2,769 5/4/2022
0.1.0 1,782 5/4/2022
0.1.0-preview-20220504-072339 1,658 5/4/2022
0.1.0-preview-20220504-050757 1,796 5/4/2022
0.1.0-preview-20220503-161347 1,676 5/3/2022