dotnet-execute 0.33.0-preview-20251015-123253

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.33.0-preview-20251015-123253
                    
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.33.0-preview-20251015-123253
                    
This package contains a .NET tool you can call from the shell/command line.
#tool dotnet:?package=dotnet-execute&version=0.33.0-preview-20251015-123253&prerelease
                    
nuke :add-package dotnet-execute --version 0.33.0-preview-20251015-123253
                    

dotnet-exec

A powerful command-line tool for executing C# programs without project files, featuring custom entry points, REPL mode, comprehensive reference management, and integrated testing capabilities.

🎯 Overview

dotnet-exec simplifies C# development by allowing you to:

  • Execute C# code directly from command line or files
  • Use custom entry points beyond the traditional Main method
  • Access REPL mode for interactive C# development
  • Reference NuGet packages, local DLLs, and frameworks seamlessly
  • Run xUnit tests without project setup
  • Save configurations as reusable profiles
  • Create aliases for frequently used commands
  • Work with remote scripts via URLs

πŸ“¦ Package Information

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

default Docker Pulls GitHub Commit Activity GitHub Release BuiltWithDot.Net shield Ask DeepWiki

πŸ“– Documentation: English | 中文介绍

πŸš€ Quick Start

Installation

# Install latest stable version
dotnet tool install -g dotnet-execute

# Install latest preview version
dotnet tool install -g dotnet-execute --prerelease

# Update to latest version
dotnet tool update -g dotnet-execute

Basic Usage

# Execute simple expressions
dotnet-exec "1 + 1"
dotnet-exec "Guid.NewGuid()"
dotnet-exec "DateTime.Now"

# Execute C# statements
dotnet-exec 'Console.WriteLine("Hello, dotnet-exec!");'

# Execute script files
dotnet-exec MyScript.cs

# Execute remote scripts
dotnet-exec https://raw.githubusercontent.com/user/repo/main/script.cs

# Start REPL mode
dotnet-exec

✨ Key Features

🎯 Multiple Execution Modes

  • Raw Code: Execute C# expressions and statements directly
  • Script Files: Run local .cs files with custom entry points
  • Remote Scripts: Execute scripts from URLs
  • REPL Mode: Interactive C# development environment

πŸ“š Rich Reference Support

  • NuGet Packages: Latest or specific versions
  • Local Assemblies: DLL files and folder references
  • Project References: Inherit dependencies from .csproj files
  • Framework References: Web, desktop, and custom frameworks

πŸ§ͺ Integrated Testing

  • xUnit Integration: Run tests without project setup
  • Test Discovery: Automatic test method detection
  • Custom References: Add packages for testing scenarios

βš™οΈ Configuration Management

  • Profiles: Save and reuse common configurations
  • Aliases: Create shortcuts for frequent commands
  • Environment Variables: Set execution context

πŸ› οΈ Developer-Friendly

  • Custom Entry Points: Use methods beyond Main
  • Preview Features: Access latest C# language features
  • Debug Mode: Detailed compilation and execution information
  • Container Support: Docker/Podman execution without .NET SDK

πŸ“– Usage Examples

Basic Execution

# Simple calculations
dotnet-exec "Math.Sqrt(16)"
dotnet-exec "string.Join(\", \", new[] {\"a\", \"b\", \"c\"})"

# Working with dates
dotnet-exec "DateTime.Now.AddDays(7).ToString(\"yyyy-MM-dd\")"

# File operations
dotnet-exec "Directory.GetFiles(\".\", \"*.cs\").Length"

Script Files with Custom Entry Points

Create example.cs:

public class Example
{
    public static void MainTest()
    {
        Console.WriteLine("Custom entry point executed!");
    }
    
    public static void Execute()
    {
        Console.WriteLine("Alternative entry method");
    }
}
# Use custom entry point
dotnet-exec example.cs --entry MainTest

References and Using Statements

# NuGet package references
dotnet-exec 'JsonConvert.SerializeObject(new {name="test"})' \
  -r 'nuget:Newtonsoft.Json' \
  -u 'Newtonsoft.Json'

# Multiple references
dotnet-exec MyScript.cs \
  -r 'nuget:Serilog' \
  -r 'nuget:AutoMapper' \
  -u 'Serilog' \
  -u 'AutoMapper'

# Local DLL references
dotnet-exec MyScript.cs -r './libs/MyLibrary.dll'

# Framework references
dotnet-exec 'WebApplication.Create().Run();' --web

REPL Mode

# Start interactive mode
dotnet-exec

# In REPL:
> #r "nuget:Newtonsoft.Json"
> using Newtonsoft.Json;
> var obj = new { Name = "Test", Value = 42 };
> JsonConvert.SerializeObject(obj)
"{"Name":"Test","Value":42}"

Testing

Execute xUnit tests without project setup:

# Run test file
dotnet-exec test MyTests.cs

# Run multiple test files
dotnet-exec test Test1.cs Test2.cs Test3.cs

# Run tests with additional references
dotnet-exec test MyTests.cs \
  -r 'nuget:Moq' \
  -r 'nuget:FluentAssertions' \
  -u 'Moq' \
  -u 'FluentAssertions'

Example test file:

public class CalculatorTests
{
    [Fact]
    public void Add_TwoNumbers_ReturnsSum()
    {
        var result = 2 + 3;
        Assert.Equal(5, result);
    }
    
    [Theory]
    [InlineData(1, 2, 3)]
    [InlineData(0, 0, 0)]
    [InlineData(-1, 1, 0)]
    public void Add_VariousInputs_ReturnsExpected(int a, int b, int expected)
    {
        var result = a + b;
        Assert.Equal(expected, result);
    }
}

Configuration Profiles

Save common configurations for reuse:

# Create a web development profile
dotnet-exec profile set webdev \
  --web \
  -r 'nuget:Swashbuckle.AspNetCore' \
  -r 'nuget:AutoMapper' \
  -u 'AutoMapper'

# List profiles
dotnet-exec profile ls

# Use profile
dotnet-exec MyWebScript.cs --profile webdev

# Get profile details
dotnet-exec profile get webdev

# Remove profile
dotnet-exec profile rm webdev

Command Aliases

Create shortcuts for frequently used commands:

# Create aliases
dotnet-exec alias set guid "Guid.NewGuid()"
dotnet-exec alias set now "DateTime.Now"
dotnet-exec alias set sha256 "Convert.ToHexString(System.Security.Cryptography.SHA256.HashData(Encoding.UTF8.GetBytes(args[0]))).Dump();"
dotnet-exec alias set base64 "Convert.ToBase64String(Encoding.UTF8.GetBytes(args[0])).Dump();"

# List aliases
dotnet-exec alias ls

# Use aliases
dotnet-exec guid
dotnet-exec now
dotnet-exec sha256 -- "text to hash"
dotnet-exec base64 -- "text to encode"

# Remove alias
dotnet-exec alias unset guid

Container Support

Execute with Docker/Podman without .NET SDK:

# Docker
docker run --rm weihanli/dotnet-exec:latest "1+1"
docker run --rm weihanli/dotnet-exec:latest "Guid.NewGuid()"
docker run --rm weihanli/dotnet-exec:latest "DateTime.Now"

# Podman
podman run --rm weihanli/dotnet-exec:latest "1+1"

# Mount local files
docker run --rm -v $(pwd):/workspace weihanli/dotnet-exec:latest MyScript.cs

For the full image tag list, see https://hub.docker.com/r/weihanli/dotnet-exec/tags

πŸ“š Documentation

Comprehensive Guides

Quick Reference

# Get help
dotnet-exec --help
dotnet-exec profile --help
dotnet-exec alias --help
dotnet-exec test --help

# Tool/Runtime information
dotnet-exec info / dotnet-exec --info

🎀 Presentations

πŸ”— GitHub Actions Integration

Execute C# code in CI/CD without .NET SDK setup:

Example usage:

- name: Execute C# Script
  uses: WeihanLi/dotnet-exec-action@main
  with:
    script: 'Console.WriteLine("Hello from GitHub Actions!");'

πŸ™ Acknowledgements

πŸ“„ License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

πŸ› Issues & Support


⭐ If you find this project helpful, please consider giving it a star!

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 542 11/20/2025
0.33.0-preview-20251113-005230 289 11/13/2025
0.33.0-preview-20251015-123253 324 10/15/2025
0.32.0 1,764 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 696 8/17/2025
0.31.0-preview-20250814-173628 197 8/14/2025
0.30.0 1,094 7/25/2025
0.30.0-preview-20250725-024058 493 7/25/2025
0.30.0-preview-20250724-010253 517 7/24/2025
0.30.0-preview-20250723-170211 557 7/23/2025
0.30.0-preview-20250723-163836 570 7/23/2025
0.30.0-preview-20250723-155751 567 7/23/2025
0.30.0-preview-20250723-154642 563 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,064 6/14/2025
0.29.0-preview-20250614-064855 184 6/14/2025
0.29.0-preview-20250611-150843 337 6/11/2025
0.29.0-preview-20250611-014826 335 6/11/2025
0.29.0-preview-20250609-171136 307 6/9/2025
0.28.0 867 5/22/2025
0.28.0-preview-20250516-140312 290 5/16/2025
0.28.0-preview-20250412-015004 372 4/12/2025
0.28.0-preview-20250330-151243 367 3/30/2025
0.27.0 1,875 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 870 3/8/2025
0.26.0-preview-20250308-054159 313 3/8/2025
0.26.0-preview-20250308-052015 293 3/8/2025
0.26.0-preview-20250306-003649 296 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 402 2/13/2025
0.26.0-preview-20250104-155937 412 1/4/2025
0.25.0 3,097 12/15/2024
0.25.0-preview-20241206-154703 386 12/6/2024
0.25.0-preview-20241205-003755 219 12/5/2024
0.25.0-preview-20241205-001213 170 12/5/2024
0.24.0 1,752 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 514 10/25/2024
0.24.0-preview-20241010-163230 335 10/10/2024
0.24.0-preview-20241009-161812 409 10/9/2024
0.24.0-preview-20241009-152619 256 10/9/2024
0.24.0-preview-20241004-001036 423 10/4/2024
0.24.0-preview-20241003-015422 332 10/3/2024
0.24.0-preview-20241002-173926 324 10/2/2024
0.24.0-preview-20240918-153023 407 9/18/2024
0.24.0-preview-20240911-171636 284 9/11/2024
0.23.0 3,911 8/29/2024
0.23.0-preview-20240824-102835 263 8/24/2024
0.23.0-preview-20240815-002214 433 8/15/2024
0.22.0 2,141 7/10/2024
0.21.0 1,294 6/15/2024
0.20.0 695 6/6/2024
0.19.0 1,843 4/21/2024
0.18.1 2,642 3/2/2024
0.18.0 854 3/1/2024
0.17.0 1,212 2/6/2024
0.16.0 1,549 1/5/2024
0.15.0 1,618 11/23/2023
0.14.0 2,170 4/22/2023
0.13.0 2,096 3/16/2023
0.12.0 2,203 12/3/2022
0.11.0 2,101 11/22/2022
0.10.0 2,021 11/15/2022
0.9.0 2,040 11/9/2022
0.8.0 2,197 10/26/2022
0.7.0 2,302 7/17/2022
0.6.0 2,417 7/1/2022
0.5.0 2,340 6/26/2022
0.4.0 2,354 6/18/2022
0.3.0 2,818 6/5/2022
0.2.0 2,526 5/29/2022
0.1.1 4,944 5/4/2022
0.1.0 2,713 5/4/2022