{"id":21817847,"url":"https://github.com/weihanli/dotnet-exec","last_synced_at":"2026-01-23T17:13:25.839Z","repository":{"id":37273664,"uuid":"488283470","full_name":"WeihanLi/dotnet-exec","owner":"WeihanLi","description":"dotnet execute with custom entry point, another dotnet run without project file","archived":false,"fork":false,"pushed_at":"2024-04-14T04:17:10.000Z","size":5288,"stargazers_count":41,"open_issues_count":6,"forks_count":4,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-04-14T05:38:03.777Z","etag":null,"topics":["csharp","csharp-script","dotnet","dotnet-exec","dotnet-execute","dotnet-script","execute","script"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/WeihanLi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2022-05-03T16:27:14.000Z","updated_at":"2024-04-17T18:56:56.633Z","dependencies_parsed_at":"2023-02-06T05:45:24.398Z","dependency_job_id":"9482576a-483e-46eb-b87f-24f2cd263e07","html_url":"https://github.com/WeihanLi/dotnet-exec","commit_stats":{"total_commits":369,"total_committers":1,"mean_commits":369.0,"dds":0.0,"last_synced_commit":"8e252a1b50d81cc38c2c3960f1bce4b98d2d987b"},"previous_names":[],"tags_count":20,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WeihanLi%2Fdotnet-exec","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WeihanLi%2Fdotnet-exec/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WeihanLi%2Fdotnet-exec/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WeihanLi%2Fdotnet-exec/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/WeihanLi","download_url":"https://codeload.github.com/WeihanLi/dotnet-exec/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230501172,"owners_count":18236061,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["csharp","csharp-script","dotnet","dotnet-exec","dotnet-execute","dotnet-script","execute","script"],"created_at":"2024-11-27T15:48:46.645Z","updated_at":"2026-01-23T17:13:25.834Z","avatar_url":"https://github.com/WeihanLi.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# dotnet-exec\n\nA powerful command-line tool for executing C# programs without project files, featuring custom entry points, REPL mode, comprehensive reference management, and integrated testing capabilities.\n\n## 🎯 Overview\n\n`dotnet-exec` simplifies C# development by allowing you to:\n\n- **Execute C# code directly** from command line or files\n- **Use custom entry points** beyond the traditional `Main` method\n- **Access REPL mode** for interactive C# development\n- **Reference NuGet packages, local DLLs, and frameworks** seamlessly\n- **Run xUnit tests** without project setup\n- **Save configurations** as reusable profiles\n- **Create aliases** for frequently used commands\n- **Work with remote scripts** via URLs\n\n## 📦 Package Information\n\nPackage | Latest | Latest Preview\n---- | ---- | ----\ndotnet-execute | [![dotnet-execute](https://img.shields.io/nuget/v/dotnet-execute)](https://www.nuget.org/packages/dotnet-execute/) | [![dotnet-execute Latest](https://img.shields.io/nuget/vpre/dotnet-execute)](https://www.nuget.org/packages/dotnet-execute/absoluteLatest)\nReferenceResolver | [![ReferenceResolver](https://img.shields.io/nuget/v/ReferenceResolver)](https://www.nuget.org/packages/ReferenceResolver/) | [![ReferenceResolver Latest](https://img.shields.io/nuget/vpre/ReferenceResolver)](https://www.nuget.org/packages/ReferenceResolver/absoluteLatest)\n\n[![default](https://github.com/WeihanLi/dotnet-exec/actions/workflows/dotnet.yml/badge.svg)](https://github.com/WeihanLi/dotnet-exec/actions/workflows/dotnet.yml)\n[![Docker Pulls](https://img.shields.io/docker/pulls/weihanli/dotnet-exec)](https://hub.docker.com/r/weihanli/dotnet-exec)\n[![GitHub Commit Activity](https://img.shields.io/github/commit-activity/m/WeihanLi/dotnet-exec)](https://github.com/WeihanLi/dotnet-exec/commits/main)\n[![GitHub Release](https://img.shields.io/github/v/release/WeihanLi/dotnet-exec)](https://github.com/WeihanLi/dotnet-exec/releases)\n[![BuiltWithDot.Net shield](https://builtwithdot.net/project/5741/dotnet-exec/badge)](https://builtwithdot.net/project/5741/dotnet-exec)\n[![Ask DeepWiki](https://deepwiki.com/badge.svg)](https://deepwiki.com/WeihanLi/dotnet-exec)\n\n**📖 Documentation**: [English](./docs/index.md) | [中文介绍](./README.zh.md)\n\n## 🚀 Quick Start\n\n### Installation\n\nInstall latest stable version\n```sh\ndotnet tool install -g dotnet-execute\n```\n\nInstall latest preview version\n```sh\ndotnet tool install -g dotnet-execute --prerelease\n```\n\nUpdate to latest version\n```sh\ndotnet tool update -g dotnet-execute\n```\n\nUpdate to latest preview version\n```sh\ndotnet tool update -g dotnet-execute --prerelease\n```\n\n\n### Basic Usage\n\n```sh\n# Execute simple expressions\ndotnet-exec \"1 + 1\"\ndotnet-exec \"Guid.NewGuid()\"\ndotnet-exec \"DateTime.Now\"\n\n# Execute C# statements\ndotnet-exec 'Console.WriteLine(\"Hello, dotnet-exec!\");'\n\n# Execute script files\ndotnet-exec MyScript.cs\n\n# Execute remote scripts\ndotnet-exec https://raw.githubusercontent.com/user/repo/main/script.cs\n\n# Start REPL mode\ndotnet-exec\n```\n\n## ✨ Key Features\n\n### 🎯 Multiple Execution Modes\n- **Raw Code**: Execute C# expressions and statements directly\n- **Script Files**: Run local .cs files with custom entry points\n- **Remote Scripts**: Execute scripts from URLs\n- **REPL Mode**: Interactive C# development environment\n\n### 📚 Rich Reference Support\n- **NuGet Packages**: Latest or specific versions\n- **Local Assemblies**: DLL files and folder references\n- **Project References**: Inherit dependencies from .csproj files\n- **Framework References**: Web, desktop, and custom frameworks\n\n### 🧪 Integrated Testing\n- **xUnit Integration**: Run tests without project setup\n- **Test Discovery**: Automatic test method detection\n- **Custom References**: Add packages for testing scenarios\n\n### ⚙️ Configuration Management\n- **Profiles**: Save and reuse common configurations\n- **Aliases**: Create shortcuts for frequent commands\n- **Environment Variables**: Set execution context\n\n### 🛠️ Developer-Friendly\n- **Custom Entry Points**: Use methods beyond `Main`\n- **Preview Features**: Access latest C# language features\n- **Debug Mode**: Detailed compilation and execution information\n- **Container Support**: Docker/Podman execution without .NET SDK\n\n## 📖 Usage Examples\n\n### Basic Execution\n\n```sh\n# Simple calculations\ndotnet-exec \"Math.Sqrt(16)\"\ndotnet-exec \"string.Join(\\\", \\\", new[] {\\\"a\\\", \\\"b\\\", \\\"c\\\"})\"\n\n# Working with dates\ndotnet-exec \"DateTime.Now.AddDays(7).ToString(\\\"yyyy-MM-dd\\\")\"\n\n# File operations\ndotnet-exec \"Directory.GetFiles(\\\".\\\", \\\"*.cs\\\").Length\"\n```\n\n### Script Files with Custom Entry Points\n\nCreate `example.cs`:\n```csharp\npublic class Example\n{\n    public static void MainTest()\n    {\n        Console.WriteLine(\"Custom entry point executed!\");\n    }\n    \n    public static void Execute()\n    {\n        Console.WriteLine(\"Alternative entry method\");\n    }\n}\n```\n\n```sh\n# Use custom entry point\ndotnet-exec example.cs --entry MainTest\n```\n\n### References and Using Statements\n\n```sh\n# NuGet package references\ndotnet-exec 'JsonConvert.SerializeObject(new {name=\"test\"})' \\\n  -r 'nuget:Newtonsoft.Json' \\\n  -u 'Newtonsoft.Json'\n\n# Multiple references\ndotnet-exec MyScript.cs \\\n  -r 'nuget:Serilog' \\\n  -r 'nuget:AutoMapper' \\\n  -u 'Serilog' \\\n  -u 'AutoMapper'\n\n# Local DLL references\ndotnet-exec MyScript.cs -r './libs/MyLibrary.dll'\n\n# Framework references\ndotnet-exec 'WebApplication.Create().Run();' --web\n```\n\n### REPL Mode\n\n```sh\n# Start interactive mode\ndotnet-exec\n\n# In REPL:\n\u003e #r \"nuget:Newtonsoft.Json\"\n\u003e using Newtonsoft.Json;\n\u003e var obj = new { Name = \"Test\", Value = 42 };\n\u003e JsonConvert.SerializeObject(obj)\n\"{\"Name\":\"Test\",\"Value\":42}\"\n```\n\n### Testing\n\nExecute xUnit tests without project setup:\n\n```sh\n# Run test file\ndotnet-exec test MyTests.cs\n\n# Run multiple test files\ndotnet-exec test Test1.cs Test2.cs Test3.cs\n\n# Run tests with additional references\ndotnet-exec test MyTests.cs \\\n  -r 'nuget:Moq' \\\n  -r 'nuget:FluentAssertions' \\\n  -u 'Moq' \\\n  -u 'FluentAssertions'\n```\n\nExample test file:\n```csharp\npublic class CalculatorTests\n{\n    [Fact]\n    public void Add_TwoNumbers_ReturnsSum()\n    {\n        var result = 2 + 3;\n        Assert.Equal(5, result);\n    }\n    \n    [Theory]\n    [InlineData(1, 2, 3)]\n    [InlineData(0, 0, 0)]\n    [InlineData(-1, 1, 0)]\n    public void Add_VariousInputs_ReturnsExpected(int a, int b, int expected)\n    {\n        var result = a + b;\n        Assert.Equal(expected, result);\n    }\n}\n```\n\n### Configuration Profiles\n\nSave common configurations for reuse:\n\n```sh\n# Create a web development profile\ndotnet-exec profile set webdev \\\n  --web \\\n  -r 'nuget:Swashbuckle.AspNetCore' \\\n  -r 'nuget:AutoMapper' \\\n  -u 'AutoMapper'\n\n# List profiles\ndotnet-exec profile ls\n\n# Use profile\ndotnet-exec MyWebScript.cs --profile webdev\n\n# Get profile details\ndotnet-exec profile get webdev\n\n# Remove profile\ndotnet-exec profile rm webdev\n```\n\n### Command Aliases\n\nCreate shortcuts for frequently used commands:\n\n```sh\n# Create aliases\ndotnet-exec alias set guid \"Guid.NewGuid()\"\ndotnet-exec alias set now \"DateTime.Now\"\ndotnet-exec alias set sha256 \"Convert.ToHexString(System.Security.Cryptography.SHA256.HashData(Encoding.UTF8.GetBytes(args[0]))).Dump();\"\ndotnet-exec alias set base64 \"Convert.ToBase64String(Encoding.UTF8.GetBytes(args[0])).Dump();\"\n\n# List aliases\ndotnet-exec alias ls\n\n# Use aliases\ndotnet-exec guid\ndotnet-exec now\ndotnet-exec sha256 -- \"text to hash\"\ndotnet-exec base64 -- \"text to encode\"\n\n# Remove alias\ndotnet-exec alias unset guid\n```\n\n### Container Support\n\nExecute with Docker/Podman without .NET SDK:\n\n```sh\n# Docker\ndocker run --rm weihanli/dotnet-exec:latest \"1+1\"\ndocker run --rm weihanli/dotnet-exec:latest \"Guid.NewGuid()\"\ndocker run --rm weihanli/dotnet-exec:latest \"DateTime.Now\"\n\n# Podman\npodman run --rm weihanli/dotnet-exec:latest \"1+1\"\n\n# Mount local files\ndocker run --rm -v $(pwd):/workspace weihanli/dotnet-exec:latest MyScript.cs\n```\n\nFor the full image tag list, see \u003chttps://hub.docker.com/r/weihanli/dotnet-exec/tags\u003e\n\n## 📚 Documentation\n\n### Comprehensive Guides\n\n- **[Getting Started](docs/articles/en/getting-started.md)**: Installation, basic usage, and core concepts\n- **[Advanced Usage](docs/articles/en/advanced-usage.md)**: Complex scenarios and advanced features\n- **[References Guide](docs/articles/en/references-guide.md)**: Managing assemblies, packages, and dependencies\n- **[Profiles and Aliases](docs/articles/en/profiles-and-aliases.md)**: Configuration management and shortcuts\n- **[Testing Guide](docs/articles/en/testing-guide.md)**: xUnit integration and testing workflows\n- **[Examples and Use Cases](docs/articles/en/examples.md)**: Real-world examples across different domains\n- **[Troubleshooting](docs/articles/en/troubleshooting.md)**: Common issues and solutions\n\n### Quick Reference\n\n```sh\n# Get help\ndotnet-exec --help\ndotnet-exec profile --help\ndotnet-exec alias --help\ndotnet-exec test --help\n\n# Tool/Runtime information\ndotnet-exec info / dotnet-exec --info\n```\n\n## 🎤 Presentations\n\n- [Makes C# more simple -- .NET Conf China 2022](https://github.com/WeihanLi/dotnet-exec/blob/main/docs/slides/dotnet-conf-china-2022-dotnet-exec_makes_csharp_more_simple.pdf)\n- [dotnet-exec simpler C# -- .NET Conf China 2023 Watch Party Shanghai](https://github.com/WeihanLi/dotnet-exec/blob/main/docs/slides/dotnet-exec-simpler-csharp.pdf)\n\n## 🔗 GitHub Actions Integration\n\nExecute C# code in CI/CD without .NET SDK setup:\n\n- **Repository**: \u003chttps://github.com/WeihanLi/dotnet-exec-action\u003e\n- **Marketplace**: \u003chttps://github.com/marketplace/actions/dotnet-exec\u003e\n\nExample usage:\n```yaml\n- name: Execute C# Script\n  uses: WeihanLi/dotnet-exec-action@main\n  with:\n    script: 'Console.WriteLine(\"Hello from GitHub Actions!\");'\n```\n\n## 🙏 Acknowledgements\n\n- [Roslyn](https://github.com/dotnet/roslyn) - C# compiler and analysis APIs\n- [NuGet.Clients](https://github.com/NuGet/NuGet.Client) - Package management\n- [System.CommandLine](https://github.com/dotnet/command-line-api) - Command-line interface\n- [Thanks JetBrains for the open source Rider license](https://jb.gg/OpenSource?from=dotnet-exec)\n- Many thanks to all contributors and users of this project\n\n## 📄 License\n\nThis project is licensed under the Apache License 2.0 - see the [LICENSE](LICENSE) file for details.\n\n## 🤝 Contributing\n\nContributions 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.\n\n## 🐛 Issues \u0026 Support\n\n- **Report bugs**: [GitHub Issues](https://github.com/WeihanLi/dotnet-exec/issues)\n- **Ask questions**: [GitHub Issues](https://github.com/WeihanLi/dotnet-exec/issues)\n- **Documentation**: [Comprehensive Guides](docs/articles/en/)\n\n---\n\n⭐ **If you find this project helpful, please consider giving it a star!**\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fweihanli%2Fdotnet-exec","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fweihanli%2Fdotnet-exec","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fweihanli%2Fdotnet-exec/lists"}