dotnet-execute 0.11.0

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

dotnet-exec

dotnet-execute

dotnet-execute 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 Main method

Install/Update

Latest stable version:

dotnet tool update -g dotnet-execute

Latest preview version:

dotnet tool update -g dotnet-execute --prerelease

Examples

Execute local file:

dotnet-exec HttpPathJsonSample.cs

Execute 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 file with preview features:

dotnet-exec RawStringLiteral.cs --preview

Execute raw code:

dotnet-exec 'code:Console.WriteLine(1+1);'

dotnet-exec 'Console.WriteLine(1+1);'

Execute raw code with custom usings:

dotnet-exec 'code:WriteLine(1+1);' --using "static System.Console"

dotnet-exec 'WriteLine(1+1);' --using "static System.Console"

Execute raw code with custom references:

NuGet package reference:

dotnet-exec 'code:CsvHelper.GetCsvText(new[]{1,2,3}).Dump();' -r "nuget: WeihanLi.Npoi,2.3.0" -u "WeihanLi.Npoi"

Local dll reference:

dotnet-exec 'code:CsvHelper.GetCsvText(new[]{1,2,3}).Dump();' -r "./out/WeihanLi.Npoi.dll" -u "WeihanLi.Npoi"

Local dll in a folder references:

dotnet-exec 'code:CsvHelper.GetCsvText(new[]{1,2,3}).Dump();' -r "folder: ./out" -u "WeihanLi.Npoi"

Local project reference:

dotnet-exec 'code:CsvHelper.GetCsvText(new[]{1,2,3}).Dump();' -r "project: ./WeihanLi.Npoi.csproj" -u "WeihanLi.Npoi"

Execute script:

dotnet-exec 'script:1+1'

dotnet-exec '1+1'

Execute script with custom reference:

dotnet-exec 'script:Console.WriteLine(CsvHelper.GetCsvText(new[]{1,2,3}))' -r "nuget:WeihanLi.Npoi,2.4.2" -u WeihanLi.Npoi
dotnet-exec 'CsvHelper.GetCsvText(new[]{1,2,3}).Dump()' -r "nuget:WeihanLi.Npoi,2.4.2" -u WeihanLi.Npoi

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 project file

dotnet-exec 'typeof(LocalType).FullName.Dump();' --project ./Sample.csproj

Execute with docker

docker run --rm weihanli/dotnet-exec:latest dotnet-exec "1+1"
docker run --rm weihanli/dotnet-exec:latest dotnet-exec "Guid.NewGuid()"
docker run --rm --pull=always weihanli/dotnet-exec:latest dotnet-exec "ApplicationHelper.RuntimeInfo"

More

LanguageVersion

By default, it's using the latest language version, you can use the Preview version with --preview

EntryPoint

By default, it would use MainTest as the entry point, you can customize with --entry option

TargetFramework

By default, it would use net7.0 if you've installed .NET 7 SDK, otherwise use .NET 6 instead, you can customize with the -f/--framework option

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

This package has no dependencies.

Version Downloads Last updated
0.24.0-preview-20241117-021926 94 11/17/2024
0.24.0-preview-20241025-003522 421 10/25/2024
0.24.0-preview-20241010-163230 224 10/10/2024
0.24.0-preview-20241009-161812 247 10/9/2024
0.24.0-preview-20241009-152619 164 10/9/2024
0.24.0-preview-20241004-001036 327 10/4/2024
0.24.0-preview-20241003-015422 233 10/3/2024
0.24.0-preview-20241002-173926 195 10/2/2024
0.24.0-preview-20240918-153023 305 9/18/2024
0.24.0-preview-20240911-171636 215 9/11/2024
0.23.0 3,557 8/29/2024
0.23.0-preview-20240824-102835 195 8/24/2024
0.23.0-preview-20240815-002214 341 8/15/2024
0.22.0 2,006 7/10/2024
0.21.0 1,165 6/15/2024
0.20.0 559 6/6/2024
0.19.0 1,748 4/21/2024
0.18.1 2,514 3/2/2024
0.18.0 729 3/1/2024
0.17.0 1,095 2/6/2024
0.16.0 1,442 1/5/2024
0.15.0 1,509 11/23/2023
0.14.0 2,043 4/22/2023
0.13.0 1,931 3/16/2023
0.12.0 2,066 12/3/2022
0.11.0 1,952 11/22/2022
0.10.0 1,900 11/15/2022
0.9.0 1,865 11/9/2022
0.8.0 2,062 10/26/2022
0.7.0 2,170 7/17/2022
0.6.0 2,286 7/1/2022
0.5.0 2,211 6/26/2022
0.4.0 2,197 6/18/2022
0.3.0 2,655 6/5/2022
0.2.0 2,365 5/29/2022
0.1.1 4,759 5/4/2022
0.1.0 2,562 5/4/2022