{"id":13490497,"url":"https://github.com/scriptcs/scriptcs","last_synced_at":"2025-04-12T14:11:45.419Z","repository":{"id":7171973,"uuid":"8473240","full_name":"scriptcs/scriptcs","owner":"scriptcs","description":"Write C# apps with a text editor, nuget and the power of Roslyn!","archived":false,"fork":false,"pushed_at":"2023-07-17T12:31:57.000Z","size":24989,"stargazers_count":2482,"open_issues_count":169,"forks_count":370,"subscribers_count":144,"default_branch":"dev","last_synced_at":"2025-04-05T12:01:35.063Z","etag":null,"topics":["csx","roslyn","scriptcs"],"latest_commit_sha":null,"homepage":"http://scriptcs.net","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/scriptcs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2013-02-28T06:27:22.000Z","updated_at":"2025-04-04T11:57:35.000Z","dependencies_parsed_at":"2024-01-02T22:38:32.057Z","dependency_job_id":"0aadd14c-6330-4772-9c99-50f10ac73807","html_url":"https://github.com/scriptcs/scriptcs","commit_stats":{"total_commits":1417,"total_committers":68,"mean_commits":20.83823529411765,"dds":0.7141848976711362,"last_synced_commit":"fc0f0280fe9cda4941ce8f2a1f031245ab978f48"},"previous_names":[],"tags_count":26,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scriptcs%2Fscriptcs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scriptcs%2Fscriptcs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scriptcs%2Fscriptcs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scriptcs%2Fscriptcs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/scriptcs","download_url":"https://codeload.github.com/scriptcs/scriptcs/tar.gz/refs/heads/dev","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248578871,"owners_count":21127713,"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":["csx","roslyn","scriptcs"],"created_at":"2024-07-31T19:00:47.576Z","updated_at":"2025-04-12T14:11:45.396Z","avatar_url":"https://github.com/scriptcs.png","language":"C#","readme":"# scriptcs\n\n[![Chocolatey Version](http://img.shields.io/chocolatey/v/scriptcs.svg?style=flat-square)](http://chocolatey.org/packages/scriptcs) [![Chocolatey Downloads](http://img.shields.io/chocolatey/dt/scriptcs.svg?style=flat-square)](http://chocolatey.org/packages/scriptcs) [![NuGet version (ScriptCs.Hosting)](https://img.shields.io/nuget/v/ScriptCs.Hosting.svg?style=flat-square)](https://www.nuget.org/packages/ScriptCs.Hosting/)\n\n[![*nix Build Status](http://img.shields.io/travis/scriptcs/scriptcs/dev.svg?style=flat-square\u0026label=linux-build)](https://travis-ci.org/scriptcs/scriptcs) [![Windows Build Status](http://img.shields.io/teamcity/codebetter/Scriptcs_Ci.svg?style=flat-square\u0026label=windows-build)](http://ci.scriptcs.net) [![Coverity Scan Build Status](https://img.shields.io/badge/coverity-passed-brightgreen.svg?style=flat-square)](https://scan.coverity.com/projects/2356)\n\n[![Issue Stats](http://issuestats.com/github/scriptcs/scriptcs/badge/pr?style=flat-square)](http://issuestats.com/github/scriptcs/scriptcs) [![Issue Stats](http://issuestats.com/github/scriptcs/scriptcs/badge/issue?style=flat-square)](http://issuestats.com/github/scriptcs/scriptcs)\n\n## What is it?\n\nscriptcs makes it easy to write and execute C# with a simple text editor.\n\nWhile Visual Studio, and other IDEs, are powerful tools, they can sometimes hinder productivity more than they promote it. You don’t always need, or want, the overhead of a creating a new solution or project. Sometimes you want to just type away in your favorite text editor.\n\nscriptcs frees you from Visual Studio, without sacrificing the advantages of a strongly-typed language. \n\n* Write C# in your favorite text editor.\n* Use NuGet to manage your dependencies.\n* The relaxed C# scripting syntax means you can write and execute an application with only one line of code. \n* Script Packs allow you to bootstrap the environment for new scripts, further reduces the amount of code necessary to take advantage of your favorite C# frameworks.\n\n\n## Getting scriptcs\n\nReleases and nightly builds should be installed using [Chocolatey](http://chocolatey.org/). To install Chocolatey, execute the following command in your command prompt:\n\n    @powershell -NoProfile -ExecutionPolicy Unrestricted -Command \"iex ((New-Object Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))\" \u0026\u0026 SET PATH=%PATH%;%systemdrive%\\chocolatey\\bin\n\nIf the above fails with the error indicating that proxy authentication is required (i.e. [HTTP 407](http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.8)) then try again with the following on the command prompt that uses your default credentials:\n\n    @powershell -NoProfile -ExecutionPolicy Unrestricted -Command \"[Net.WebRequest]::DefaultWebProxy.Credentials = [Net.CredentialCache]::DefaultCredentials; iex ((New-Object Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))\" \u0026\u0026 SET PATH=%PATH%;%systemdrive%\\chocolatey\\bin\n\n**Note:** If you are using a version of Chocolatey \u003e 0.9.9.0 you can pass the `-y` into the install and upgrade commands to prevent the confirmation that will appear.\n\n### Installing scriptcs\n\nOnce Chocolatey has been installed, you can install the latest stable version of scriptcs from your command prompt:\n\n    choco install scriptcs\n\nChocolatey will install scriptcs to `%LOCALAPPDATA%\\scriptcs\\` and update your PATH accordingly.\n\n**Note:** You may need to restart your command prompt after the installation completes.\n\n### Staying up-to-date\n\nWith Chocolatey, keeping scriptcs updated is just as easy:\n\n    choco upgrade scriptcs\n\n**Note:** If you are using a version of Chocolatey \u003c 0.9.0.0 you will need to use `choco update scriptcs`, but also think about updating Chocolatey itself.\n\n### Nightly builds\n\nNightly builds are hosted on [MyGet](https://www.myget.org/), and can also be installed through with Chocolatey:\n\n    choco install scriptcs -pre -source https://www.myget.org/F/scriptcsnightly/ \n\n### Building from source\n\n#### Windows\n\n1. Ensure you have .NET Framework 4.6.1 installed.\n\n2. Execute the build script.\n\n    `build.cmd`\n\n#### Linux\n\n1. Ensure you have [Mono 5.12](https://www.mono-project.com/download/stable/) or later installed.\n    \n2. Execute the build script\n\n    `./build.sh`\n\n## Getting Started\n\n### Using the REPL\nThe scriptcs REPL can be started by running scriptcs without any parameters. The REPL allows you to execute C# statements directly from your command prompt.\n\n```batchfile\nC:\\\u003e scriptcs\nscriptcs (ctrl-c or blank to exit)\n\n\u003e var message = \"Hello, world!\";\n\u003e Console.WriteLine(message);\nHello, world!\n\u003e \n\nC:\\\u003e\n```\n\nREPL supports all C# language constructs (i.e. class definition, method definition), as well as multi-line input. For example:\n\n```batchfile\nC:\\\u003e scriptcs\nscriptcs (ctrl-c or blank to exit)\n\n\u003e public class Test {\n    public string Name { get; set; }\n  }\n\u003e var x = new Test { Name = \"Hello\" };\n\u003e x\n{Name: \"Hello\"}\n\nC:\\\u003e\n```\n\n### Writing a script\n\n* In an empty directory, create a new file named `app.csx`:\n\n```c#\nusing Raven.Client;\nusing Raven.Client.Embedded;\nusing Raven.Client.Indexes;\n\nConsole.WriteLine(\"Starting RavenDB server...\");\n\nusing (var documentStore = new EmbeddableDocumentStore { UseEmbeddedHttpServer = true })\n{\n    documentStore.Initialize();\n    Console.WriteLine($\"RavenDB started, listening on http://localhost:{documentStore.Configuration.Port}\");\n    Console.ReadKey();\n}\n```\n\n* Install the [RavenDB.Embedded](https://nuget.org/packages/RavenDB.Embedded/) package from NuGet using the [install command](https://github.com/scriptcs/scriptcs/wiki/Package-installation).\n\n```batchfile\nscriptcs -install RavenDB.Embedded\n```\n\n* Execute your script. Note that listening on a port requires that the command prompt be launched using the **Run as Administrator** option.\n\n```batchfile\n\u003e scriptcs app.csx\nINFO : Starting to create execution components\nINFO : Starting execution\nStarting RavenDB server...\n.. snip ..\nRavenDB started, listening on http://localhost:8080.\n```\n\n* Navigating to the URL that Raven is listening on will now bring up the RavenDB management studio.\n\n### Bootstrap scripts with Script Packs\n\nScript Packs can be used to further reduce the amount of code you need to write when working with common frameworks. \n\n* In an empty directory, install the [ScriptCs.WebApi](https://nuget.org/packages/ScriptCs.WebApi/) script pack from NuGet. The script pack automatically imports the Web API namespaces and provides a convenient factory method for initializing the Web API host. It also replaces the default `ControllerResolver` with a custom implementation that allows Web API to discover controllers declared in scripts.\n\n```batchfile\nscriptcs -install ScriptCs.WebApi\n```\n\n* Script packs can be imported into a script by calling `Require\u003cTScriptPack\u003e()`. Create a file named `server.csx` that contains the following code:\n\n```c#\npublic class TestController : ApiController {\n    public string Get() {\n        return \"Hello world!\";\n    }\n}\n\nvar webApi = Require\u003cWebApi\u003e();\nvar server = webApi.CreateServer(\"http://localhost:8888\");\nserver.OpenAsync().Wait();\n\nConsole.WriteLine(\"Listening...\");\nConsole.ReadKey();\nserver.CloseAsync().Wait();\n```\n\n* In a command prompt running as administrator, execute the `server.csx` file.\n\n```batchfile\nscriptcs server.csx \n```\n\n* Browse to http://localhost:8888/test/ to see the result of the TestController.Get method.\n\n```xml\n\u003cstring xmlns=\"http://schemas.microsoft.com/2003/10/Serialization/\"\u003eHello world!\u003c/string\u003e\n```\n\n### Referencing scripts\n\n* Move the TestController class from the previous example into a new file named `controller.csx` with the following content.\n\n* On the first line of `server.csx`, reference `controller.csx` using the [#load directive](https://github.com/scriptcs/scriptcs/wiki/Writing-a-script#loading-referenced-scripts). **Note:** #load directives must be placed at the top of a script, otherwise they will be ignored.\n\n```c#\n#load \"controller.csx\"\n```\n\n* In a command prompt running as administrator, execute the `server.csx` file.\n\n```batchfile\nscriptcs server.csx \n```\n\n* Browse to http://localhost:8888/test/ to see the result of the TestController.Get method.\n\n```xml\n\u003cstring xmlns=\"http://schemas.microsoft.com/2003/10/Serialization/\"\u003eHello world!\u003c/string\u003e\n```\n\n\n### Referencing assemblies\n\nYou can reference additional assemblies from the GAC or from the `bin` folder in your script's directory using the [#r directive](https://github.com/scriptcs/scriptcs/wiki/Writing-a-script#referencing-assemblies):\n\n```c#\n#r \"nunit.core.dll\"\n#r \"nunit.core.interfaces.dll\"\n\nvar path = \"UnitTests.dll\";\nvar runner = TestSetup.GetRunner(new[] {path});\nvar result = runner.Run(new ConsoleListener(msg =\u003e Console.WriteLine(msg)), TestFilter.Empty, true,     LoggingThreshold.All);\n\nConsole.ReadKey();\n```\n\n### Debugging\n\nInstructions for debugging scripts using Visual Studio can be found on the [wiki](https://github.com/scriptcs/scriptcs/wiki/Debugging-a-script).\n\n### Package installation\n\nYou can install any NuGet packages directly from the scriptcs CLI. This will pull the relevant packages from NuGet, and install them in the scriptcs_packages folder.\n\nOnce the packages are installed, you can simply start using them in your script code directly (just import the namespaces - no additional bootstrapping or DLL referencing is needed).\n\nThe `install` command will also create a `scriptcs_packages.config` file if you don't have one - so that you can easily redistribute your script (without having to copy the package binaries).\n\n - `scriptcs -install {package name}` will install the desired package from NuGet. \n \t\n\tFor example: \n\n\t\tscriptcs -install ServiceStack\n\t\t\n - `scriptcs -install` (without package name) will look for the `scriptcs_packages.config` file located in the current execution directory, and install all the packages specified there. You only need to specify **top level** packages.\n\nFor example, you might create the following `scriptcs_packages.config`:\n\n\t\u003c?xml version=\"1.0\" encoding=\"utf-8\"?\u003e\n\t\u003cpackages\u003e\n  \t\t\u003cpackage id=\"Nancy.Hosting.Self\" version=\"0.16.1\" targetFramework=\"net40\" /\u003e\n  \t\t\u003cpackage id=\"Nancy.Bootstrappers.Autofac\" version=\"0.16.1\" targetFramework=\"net40\" /\u003e\n  \t\t\u003cpackage id=\"Autofac\" version=\"2.6.3.862\" targetFramework=\"net40\" /\u003e\n\t\u003c/packages\u003e\n\nAnd then just call:\n\n    scriptcs -install\n\nAs a result, all packages specified in the `scriptcs_packages.config`, including all dependencies, will be downloaded and installed in the `scriptcs_packages` folder. \n\n\n## Contributing\n\n* Read our [Contribution Guidelines](https://github.com/scriptcs/scriptcs/blob/master/CONTRIBUTING.md). \n\n\n## Samples and Documentation\n\nAdditional samples can be contributed to our [samples repository](https://github.com/scriptcs/scriptcs-samples). Documentation can be found on our [wiki](https://github.com/scriptcs/scriptcs/wiki). \n\n\n## Community\n\nWant to chat? In addition to Twitter, you can find us on [Google Groups](https://groups.google.com/forum/?fromgroups#!forum/scriptcs) and [JabbR](https://jabbr.net/#/rooms/scriptcs)!\n\n\n## Coordinators\n\n* [Glenn Block](https://github.com/glennblock) ([@gblock](https://twitter.com/intent/user?screen_name=gblock))\n* [Justin Rusbatch](https://github.com/jrusbatch) ([@jrusbatch](https://twitter.com/intent/user?screen_name=jrusbatch))\n* [Filip Wojcieszyn](https://github.com/filipw) ([@filip_woj](https://twitter.com/intent/user?screen_name=filip_woj))\n\n\n## Core Committers\n\n* [Damian Schenkelman](http://github.com/dschenkelman) ([@dschenkelman](https://twitter.com/intent/user?screen_name=dschenkelman))\n* [Kristian Hellang](http://github.com/khellang) ([@khellang](https://twitter.com/intent/user?screen_name=khellang))\n* [Adam Ralph](http://github.com/adamralph) ([@adamralph](https://twitter.com/intent/user?screen_name=adamralph))\n* [Paul Bouwer](http://github.com/paulbouwer) ([@pbouwer](https://twitter.com/intent/user?screen_name=pbouwer))\n\n## Credits \n\n* Check out the [list of developers](https://github.com/scriptcs/scriptcs/wiki/Contributors) responsible for getting scriptcs to where it is today! \n* Special thanks to Filip Wojcieszyn for being the inspiration behind this with his Roslyn Web API posts.\n* Thanks to the Roslyn team who helped point me in the right direction.\n\n\n## License \n\n[Apache 2 License](https://github.com/scriptcs/scriptcs/blob/master/LICENSE.md)\n","funding_links":[],"categories":["C#","C# #","others","C\\#","Misc","杂项","🗒️ Cheatsheets"],"sub_categories":["📦 Libraries"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscriptcs%2Fscriptcs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fscriptcs%2Fscriptcs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscriptcs%2Fscriptcs/lists"}