dotnet-execute 0.26.0-preview-20250304-153109

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

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 --source https://api.nuget.org/v3/index.json
dotnet tool update -g dotnet-execute --prerelease --add-source https://api.nuget.org/v3/index.json --ignore-failed-sources

Uninstall or failed to update? Try uninstall and install again

dotnet tool uninstall -g dotnet-execute

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,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();' --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,3.0.0" -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 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.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
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.33.0 774 11/20/2025
0.33.0-preview-20251113-005230 292 11/13/2025
0.33.0-preview-20251015-123253 324 10/15/2025
0.32.0 1,767 9/11/2025
0.32.0-preview-20250911-001745 186 9/11/2025
0.32.0-preview-20250825-230929 296 8/25/2025
0.31.0 698 8/17/2025
0.31.0-preview-20250814-173628 201 8/14/2025
0.30.0 1,097 7/25/2025
0.30.0-preview-20250725-024058 495 7/25/2025
0.30.0-preview-20250724-010253 518 7/24/2025
0.30.0-preview-20250723-170211 558 7/23/2025
0.30.0-preview-20250723-163836 574 7/23/2025
0.30.0-preview-20250723-155751 567 7/23/2025
0.30.0-preview-20250723-154642 566 7/23/2025
0.30.0-preview-20250723-003045 574 7/23/2025
0.30.0-preview-20250718-001208 196 7/18/2025
0.30.0-preview-20250715-051839 200 7/15/2025
0.30.0-preview-20250616-043224 263 6/16/2025
0.29.0 1,069 6/14/2025
0.29.0-preview-20250614-064855 185 6/14/2025
0.29.0-preview-20250611-150843 337 6/11/2025
0.29.0-preview-20250611-014826 336 6/11/2025
0.29.0-preview-20250609-171136 307 6/9/2025
0.28.0 870 5/22/2025
0.28.0-preview-20250516-140312 291 5/16/2025
0.28.0-preview-20250412-015004 374 4/12/2025
0.28.0-preview-20250330-151243 367 3/30/2025
0.27.0 1,877 3/29/2025
0.27.0-preview-20250329-061056 201 3/29/2025
0.27.0-preview-20250320-150236 240 3/20/2025
0.26.0 878 3/8/2025
0.26.0-preview-20250308-054159 315 3/8/2025
0.26.0-preview-20250308-052015 293 3/8/2025
0.26.0-preview-20250306-003649 298 3/6/2025
0.26.0-preview-20250304-161120 387 3/4/2025
0.26.0-preview-20250304-153109 376 3/4/2025
0.26.0-preview-20250213-145629 403 2/13/2025
0.26.0-preview-20250104-155937 412 1/4/2025
0.25.0 3,099 12/15/2024
0.25.0-preview-20241206-154703 387 12/6/2024
0.25.0-preview-20241205-003755 220 12/5/2024
0.25.0-preview-20241205-001213 171 12/5/2024
0.24.0 1,754 11/24/2024
0.24.0-preview-20241124-035720 259 11/24/2024
0.24.0-preview-20241117-021926 364 11/17/2024
0.24.0-preview-20241025-003522 515 10/25/2024
0.24.0-preview-20241010-163230 335 10/10/2024
0.24.0-preview-20241009-161812 410 10/9/2024
0.24.0-preview-20241009-152619 257 10/9/2024
0.24.0-preview-20241004-001036 423 10/4/2024
0.24.0-preview-20241003-015422 333 10/3/2024
0.24.0-preview-20241002-173926 325 10/2/2024
0.24.0-preview-20240918-153023 407 9/18/2024
0.24.0-preview-20240911-171636 287 9/11/2024
0.23.0 3,913 8/29/2024
0.23.0-preview-20240824-102835 264 8/24/2024
0.23.0-preview-20240815-002214 433 8/15/2024
0.22.0 2,143 7/10/2024
0.21.0 1,298 6/15/2024
0.20.0 699 6/6/2024
0.19.0 1,845 4/21/2024
0.18.1 2,646 3/2/2024
0.18.0 856 3/1/2024
0.17.0 1,214 2/6/2024
0.16.0 1,551 1/5/2024
0.15.0 1,621 11/23/2023
0.14.0 2,173 4/22/2023
0.13.0 2,099 3/16/2023
0.12.0 2,207 12/3/2022
0.11.0 2,109 11/22/2022
0.10.0 2,026 11/15/2022
0.9.0 2,044 11/9/2022
0.8.0 2,202 10/26/2022
0.7.0 2,305 7/17/2022
0.6.0 2,420 7/1/2022
0.5.0 2,345 6/26/2022
0.4.0 2,358 6/18/2022
0.3.0 2,822 6/5/2022
0.2.0 2,529 5/29/2022
0.1.1 4,949 5/4/2022
0.1.0 2,717 5/4/2022