{"id":13593651,"url":"https://github.com/waf/CSharpRepl","last_synced_at":"2025-04-09T05:31:51.760Z","repository":{"id":38829864,"uuid":"354291352","full_name":"waf/CSharpRepl","owner":"waf","description":"A command line C# REPL with syntax highlighting – explore the language, libraries and nuget packages interactively.","archived":false,"fork":false,"pushed_at":"2024-07-15T16:11:31.000Z","size":4624,"stargazers_count":2909,"open_issues_count":49,"forks_count":112,"subscribers_count":24,"default_branch":"main","last_synced_at":"2024-10-29T15:08:05.950Z","etag":null,"topics":["cli","console","csharp","dotnet","global-tool","interactive-programming","repl"],"latest_commit_sha":null,"homepage":"https://fuqua.io/CSharpRepl/","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/waf.png","metadata":{"files":{"readme":".github/readme_assets/csharprepl.mp4","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.txt","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,"publiccode":null,"codemeta":null}},"created_at":"2021-04-03T12:52:25.000Z","updated_at":"2024-10-28T14:04:29.000Z","dependencies_parsed_at":"2024-11-06T15:51:31.330Z","dependency_job_id":null,"html_url":"https://github.com/waf/CSharpRepl","commit_stats":{"total_commits":256,"total_committers":6,"mean_commits":"42.666666666666664","dds":0.44140625,"last_synced_commit":"9e639dc8031e201a9bc91cfa5083d48a72a435d7"},"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/waf%2FCSharpRepl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/waf%2FCSharpRepl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/waf%2FCSharpRepl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/waf%2FCSharpRepl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/waf","download_url":"https://codeload.github.com/waf/CSharpRepl/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247986805,"owners_count":21028887,"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":["cli","console","csharp","dotnet","global-tool","interactive-programming","repl"],"created_at":"2024-08-01T16:01:22.712Z","updated_at":"2025-04-09T05:31:51.393Z","avatar_url":"https://github.com/waf.png","language":"C#","readme":"\u003cdiv align=\"center\" style=\"text-align:center\"\u003e\u003ca href=\"https://www.nuget.org/packages/CSharpRepl\"\u003e\u003cimg alt=\"NuGet Version\" src=\"https://img.shields.io/nuget/v/CSharpRepl\"\u003e\u003c/a\u003e\u003c/div\u003e\r\n\r\n# C# REPL\r\n\r\nA cross-platform command line \u003ca href=\"https://en.wikipedia.org/wiki/Read%E2%80%93eval%E2%80%93print_loop\" target=\"_blank\"\u003e\u003cabbr title=\"Read Eval Print Loop\"\u003eREPL\u003c/abbr\u003e\u003c/a\u003e for the rapid experimentation and exploration of C#. It supports intellisense, installing NuGet packages, and referencing local .NET projects and assemblies.\r\n\r\n\u003cdiv align=\"center\"\u003e\r\n  \u003ca href=\"https://raw.githubusercontent.com/waf/CSharpRepl/main/.github/readme_assets/csharprepl.mp4\"\u003e\r\n    \u003cimg src=\"https://raw.githubusercontent.com/waf/CSharpRepl/main/.github/readme_assets/csharprepl.png\" alt=\"C# REPL screenshot\" style=\"max-width:80%;\"\u003e\r\n  \u003c/a\u003e\r\n  \u003cp align=\"center\"\u003e\u003ci\u003e(click to view animation)\u003c/i\u003e\u003c/p\u003e\r\n\u003c/div\u003e\r\n\r\nC# REPL provides the following features:\r\n\r\n- Syntax highlighting via ANSI escape sequences\r\n- Intellisense with documentation and overload navigation\r\n- Automatic formatting of typed input\r\n- Nuget package installation\r\n- Reference local assemblies, solutions, and projects\r\n- Dump and explore objects with syntax highlighting and rich Spectre.Console formatting\r\n- OpenAI integration (bring your own API key)\r\n- Navigate to source via Source Link\r\n- IL disassembly (both Debug and Release mode)\r\n- Fast and flicker-free rendering. A \"diff\" algorithm is used to only render what's changed.\r\n\r\n## Installation\r\n\r\nC# REPL is a .NET 8 global tool, and runs on Windows, Mac OS, and Linux. It can be installed [from NuGet](https://www.nuget.org/packages/CSharpRepl) via:\r\n\r\n```console\r\ndotnet tool install -g csharprepl\r\n```\r\n\r\nIf you're running on Mac OS Catalina (10.15) or later, make sure you follow any additional directions printed to the screen. You may need to update your PATH variable in order to use .NET global tools.\r\n\r\nAfter installation is complete, run `csharprepl` to begin. C# REPL can be updated via `dotnet tool update -g csharprepl`.\r\n\r\n## Themes and Colors\r\n\r\nThe default theme uses the same colors as Visual Studio dark mode, and custom themes can be created using a [`theme.json`](https://github.com/waf/CSharpRepl/blob/main/CSharpRepl/themes/dracula.json) file. Additionally, your terminal's colors can be used by supplying the `--useTerminalPaletteTheme` command line option. To completely disable colors, set the NO_COLOR environment variable.\r\n\r\n## Usage\r\n\r\nType some C# into the prompt and press \u003ckbd\u003eEnter\u003c/kbd\u003e to run it. The result, if any, will be printed:\r\n\r\n```csharp\r\n\u003e Console.WriteLine(\"Hello World\")\r\nHello World\r\n\r\n\u003e DateTime.Now.AddDays(8)\r\n[6/7/2021 5:13:00 PM]\r\n```\r\n\r\nTo evaluate multiple lines of code, use \u003ckbd\u003eShift+Enter\u003c/kbd\u003e to insert a newline:\r\n\r\n```csharp\r\n\u003e var x = 5;\r\n  var y = 8;\r\n  x * y\r\n40\r\n```\r\n\r\nAdditionally, if the statement is not a \"complete statement\" a newline will automatically be inserted when \u003ckbd\u003eEnter\u003c/kbd\u003e is pressed. For example, in the below code, the first line is not a syntactically complete statement, so when we press enter we'll go down to a new line:\r\n\r\n```csharp\r\n\u003e if (x == 5)\r\n  | // caret position, after we press Enter on Line 1\r\n```\r\n\r\nFinally, pressing \u003ckbd\u003eCtrl+Enter\u003c/kbd\u003e will show a \"detailed view\" of the result. For example, for the `DateTime.Now` expression below, on the first line we pressed \u003ckbd\u003eEnter\u003c/kbd\u003e, and on the second line we pressed \u003ckbd\u003eCtrl+Enter\u003c/kbd\u003e to view more detailed output:\r\n\r\n```csharp\r\n\u003e DateTime.Now // Pressing Enter shows a reasonable representation\r\n[5/30/2021 5:13:00 PM]\r\n\r\n\u003e DateTime.Now // Pressing Ctrl+Enter shows a detailed representation\r\n[5/30/2021 5:13:00 PM] {\r\n  Date: [5/30/2021 12:00:00 AM],\r\n  Day: 30,\r\n  DayOfWeek: Sunday,\r\n  DayOfYear: 150,\r\n  Hour: 17,\r\n  InternalKind: 9223372036854775808,\r\n  InternalTicks: 637579915804530992,\r\n  Kind: Local,\r\n  Millisecond: 453,\r\n  Minute: 13,\r\n  Month: 5,\r\n  Second: 0,\r\n  Ticks: 637579915804530992,\r\n  TimeOfDay: [17:13:00.4530992],\r\n  Year: 2021,\r\n  _dateData: 9860951952659306800\r\n}\r\n```\r\n\r\n**A note on semicolons**: C# expressions do not require semicolons, but [statements](https://stackoverflow.com/questions/19132/expression-versus-statement) do. If a statement is missing a required semicolon, a newline will be added instead of trying to run the syntatically incomplete statement; simply type the semicolon to complete the statement.\r\n\r\n```csharp\r\n\u003e var now = DateTime.Now; // assignment statement, semicolon required\r\n\r\n\u003e DateTime.Now.AddDays(8) // expression, we don't need a semicolon\r\n[6/7/2021 5:03:05 PM]\r\n```\r\n\r\nWhen you're done with your session, you can type `exit` or press \u003ckbd\u003eCtrl+D\u003c/kbd\u003e to exit.\r\n\r\n## Adding References\r\n\r\nUse the `#r` command to add assembly or nuget references.\r\n\r\n- For assembly references, run `#r \"AssemblyName\"` or `#r \"path/to/assembly.dll\"`\r\n- For project references, run `#r \"path/to/project.csproj\"`. Solution files (.sln) can also be referenced.\r\n- For nuget references, run `#r \"nuget: PackageName\"` to install the latest version of a package, or `#r \"nuget: PackageName, 13.0.5\"` to install a specific version (13.0.5 in this case).\r\n\r\n\u003cp align=\"center\"\u003e\r\n  \u003cimg src=\"https://raw.githubusercontent.com/waf/CSharpRepl/main/.github/readme_assets/nuget.png\" alt=\"Installing nuget packages\" style=\"max-width:80%;\"\u003e\r\n\u003c/p\u003e\r\n\r\nTo run ASP.NET applications inside the REPL, start the `csharprepl ` application with the `--framework` parameter, specifying the `Microsoft.AspNetCore.App` shared framework. Then, use the above `#r` command to reference the application DLL. See [Configuring CSharpRepl](https://github.com/waf/CSharpRepl/wiki/Configuring-CSharpRepl) for more details.\r\n\r\n```console\r\ncsharprepl --framework  Microsoft.AspNetCore.App\r\n```\r\n\r\n## Keyboard Shortcuts\r\n\r\nCSharpRepl aims for a similar editing experience as Visual Studio (e.g. for text navigation, selection and keyboard shortcuts).\r\n\r\n- **Basic Usage**\r\n  - \u003ckbd\u003eCtrl+C\u003c/kbd\u003e - Cancel current line\r\n  - \u003ckbd\u003eCtrl+D\u003c/kbd\u003e or type `exit` - Exit the REPL\r\n  - \u003ckbd\u003eCtrl+L\u003c/kbd\u003e - Clear screen\r\n  - \u003ckbd\u003eEnter\u003c/kbd\u003e - Evaluate the current line if it's a syntactically complete statement; otherwise add a newline\r\n  - \u003ckbd\u003eControl+Enter\u003c/kbd\u003e - Evaluate the current line, and return a more detailed representation of the result\r\n  - \u003ckbd\u003eShift+Enter\u003c/kbd\u003e - Insert a new line (this does not currently work on Linux or Mac OS; Hopefully this will work in .NET 7)\r\n  - \u003ckbd\u003eCtrl+Shift+C\u003c/kbd\u003e - Copy current line to clipboard\r\n  - \u003ckbd\u003eCtrl+V\u003c/kbd\u003e, \u003ckbd\u003eShift+Insert\u003c/kbd\u003e, and \u003ckbd\u003eCtrl+Shift+V\u003c/kbd\u003e - Paste text to prompt. Automatically trims leading indent\r\n- **Code Actions**\r\n  - \u003ckbd\u003eF1\u003c/kbd\u003e - Opens the MSDN documentation for the class/method under the caret ([example](https://docs.microsoft.com/en-US/dotnet/api/System.DateTime.AddDays?view=net-5.0))\r\n  - \u003ckbd\u003eF9\u003c/kbd\u003e - Shows the IL (intermediate language) for the current statement in Debug mode. \r\n  - \u003ckbd\u003eCtrl+F9\u003c/kbd\u003e - Shows the IL for the current statement with Release mode optimizations.\r\n  - \u003ckbd\u003eF12\u003c/kbd\u003e - Opens the source code in the browser for the class/method under the caret, if the assembly supports [Source Link](https://github.com/dotnet/sourcelink).\r\n- **Autocompletion**\r\n  - \u003ckbd\u003eCtrl+Space\u003c/kbd\u003e - Open the autocomplete menu.\r\n  - \u003ckbd\u003eEnter\u003c/kbd\u003e, \u003ckbd\u003eTab\u003c/kbd\u003e - Select the active autocompletion option\r\n  - \u003ckbd\u003eEscape\u003c/kbd\u003e - Closes the autocomplete menu\r\n\r\n## Command Line Configuration\r\n\r\nThe C# REPL supports both command line options as well as a configuration file. See the [Configuring CSharpRepl](https://github.com/waf/CSharpRepl/wiki/Configuring-CSharpRepl) wiki page for more information.\r\n\r\nRun `csharprepl --help` to see the available command line configuration options, and run `csharprepl --configure` to get started with the configuration file.\r\n\r\nIf you have [`dotnet-suggest`](https://github.com/dotnet/command-line-api/blob/main/docs/dotnet-suggest.md) enabled, all options can be tab-completed, including values provided to `--framework` and .NET namespaces provided to `--using`.\r\n\r\n## Integrating with other software\r\n\r\nC# REPL is a standalone software application, but it can be useful to integrate it with other developer tools:\r\n\r\n### Windows Terminal\r\n\r\nTo add C# REPL as a menu entry in Windows Terminal, add the following profile to Windows Terminal's `settings.json` configuration file (under the JSON property `profiles.list`):\r\n\r\n```json\r\n{\r\n    \"name\": \"C# REPL\",\r\n    \"commandline\": \"csharprepl\"\r\n},\r\n```\r\n\r\nTo get the exact colors shown in the screenshots in this README, install the [Windows Terminal Dracula theme](https://github.com/dracula/windows-terminal).\r\n\r\n### Visual Studio Code\r\n\r\nTo use the C# REPL with Visual Studio Code, simply run the `csharprepl` command in the Visual Studio Code terminal. To send commands to the REPL, use the built-in `Terminal: Run Selected Text In Active Terminal` command from the Command Palette (`workbench.action.terminal.runSelectedText`).\r\n\r\n\u003cp align=\"center\"\u003e\r\n  \u003cimg src=\"https://raw.githubusercontent.com/waf/CSharpRepl/main/.github/readme_assets/vscode.png\" alt=\"Visual Studio Code screenshot\" style=\"max-width:90%;\"\u003e\r\n\u003c/p\u003e\r\n\r\n\r\n### Windows OS\r\n\r\nTo add the C# REPL to the Windows Start Menu for quick access, you can run the following PowerShell command, which will start C# REPL in Windows Terminal:\r\n\r\n```powershell\r\n$shell = New-Object -ComObject WScript.Shell\r\n$shortcut = $shell.CreateShortcut(\"$env:appdata\\Microsoft\\Windows\\Start Menu\\Programs\\csharprepl.lnk\")\r\n$shortcut.TargetPath = \"wt.exe\"\r\n$shortcut.Arguments = \"-w 0 nt csharprepl.exe\"\r\n$shortcut.Save()\r\n```\r\n\r\nYou may also wish to add a shorter alias for C# REPL, which can be done by creating a `.cmd` file somewhere on your path. For example, put the following contents in `C:\\Users\\username\\.dotnet\\tools\\csr.cmd`:\r\n\r\n```shell\r\nwt -w 0 nt csharprepl\r\n```\r\n\r\nThis will allow you to launch C# REPL by running `csr` from anywhere that accepts Windows commands, like the Window Run dialog.\r\n\r\n### Linux terminal)\r\n\r\nYou may wish to add a shorter alias for C# REPL, which can be done by adding the following to your `~/.bashrc`:\r\n\r\n```shell\r\nalias cs=csharprepl\r\n```\r\n\r\n## Comparison with other REPLs\r\n\r\nThis project is far from being the first REPL for C#. Here are some other projects; if this project doesn't suit you, another one might!\r\n\r\n**Visual Studio's C# Interactive pane** is full-featured (it has syntax highlighting and intellisense) and is part of Visual Studio. This deep integration with Visual Studio is both a benefit from a workflow perspective, and a drawback as it's not cross-platform. The C# Interactive pane supports navigating to source code (default F12), which will open that source in the containing Visual Studio window, yet no NuGet packages. It starts in .NET Framework mode but also supports .NET Core via `#reset core`. Subjectively, it does not follow typical command line keybindings, so can feel a bit foreign.\r\n\r\n**csi.exe** ships with C# and is a command line REPL. It's great because it's a cross platform REPL that comes out of the box, but it doesn't support syntax highlighting, autocompletion, or .NET Core.\r\n\r\n**[dotnet script](https://github.com/dotnet-script/dotnet-script)** allows you to run C# scripts from the command line. It has a REPL built-in, but the predominant focus seems to be as a script runner. It's a great tool, though, and has a strong community following.\r\n\r\n**[dotnet interactive](https://github.com/dotnet/interactive)** is a tool from Microsoft that creates a Jupyter notebook for C#, runnable through Visual Studio Code. It also provides a general framework useful for running REPLs.\r\n\r\n## Contributing\r\n\r\nThanks for the interest! Check out [CONTRIBUTING.md](https://github.com/waf/CSharpRepl/blob/main/CONTRIBUTING.md) for more info.\r\n","funding_links":[],"categories":["C#","C\\#","C# #","csharp"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwaf%2FCSharpRepl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwaf%2FCSharpRepl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwaf%2FCSharpRepl/lists"}