Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/roman-yagodin/csexec
Command-line tool to run C# source files as scripts on Linux with Mono
https://github.com/roman-yagodin/csexec
Last synced: 17 days ago
JSON representation
Command-line tool to run C# source files as scripts on Linux with Mono
- Host: GitHub
- URL: https://github.com/roman-yagodin/csexec
- Owner: roman-yagodin
- License: gpl-3.0
- Created: 2015-05-12T11:55:30.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2019-09-05T11:52:03.000Z (over 5 years ago)
- Last Synced: 2024-04-14T23:58:11.616Z (10 months ago)
- Language: C#
- Homepage:
- Size: 21.5 KB
- Stars: 3
- Watchers: 3
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# About csexec
`csexec` is command-line tool to run C# source files as scripts in Linux environments using Mono framework.
It is evolved from the original idea described here on [StackOverflow](http://stackoverflow.com/questions/20392243/run-c-sharp-code-on-linux-terminal).## Features
Major `csexec` features comparing to the Mono C# REPL (`csharp`):
* Full C# language features at your fingers!
* Ability to run script in a terminal emulator.
* Ability to pass command-line arguments to the script ([csharp also supports this since Mono 5.0.0](http://www.mono-project.com/docs/about-mono/releases/5.0.0/#csharp)).
* Script source file name is available as a first argument.## License
[![GPLv3](https://www.gnu.org/graphics/gplv3-127x51.png)](https://www.gnu.org/licenses/gpl-3.0.html)
The *csexec* is free software: you can redistribute it and/or modify it under the terms of
the GNU General Public License as published by the Free Software Foundation, either version 3 of the License,
or (at your option) any later version.## Install & prepare scripts
1. Make `csexec` executable and copy it to the `/usr/bin`:
```Shell
chmod +x csexec
sudo cp -f csexec /usr/bin
```
2. Add `#!/usr/bin/csexec` line at the beginning of C# source file.
3. Make C# source file executable.
4. Optionally, change C# source file extension to something like `.csx`.Note what `csexec` writes compiler messages to `csexec.log` file in its current working directory,
which may be not the same as a script source directory!## Basic console script
```C#
#!/usr/bin/csexecusing System;
public class Program
{
public static void Main (string [] args)
{
Console.WriteLine ("Hello, world!");
Console.WriteLine ("Arguments: " + string.Join (", ", args));
}
}
```## Run in the terminal emulator
Use `-t` switch to run script in terminal emulator window.
Consider add `Console.ReadKey ()` to the end of the program
to pause script before it quits.```C#
#!/usr/bin/csexec -tusing System;
public class Program
{
public static void Main (string [] args)
{
Console.WriteLine ("Hello, world!");
Console.WriteLine ("Arguments: " + string.Join (", ", args));Console.Write ("Press any key to quit...");
Console.ReadKey (true);
}
}
```## Reference GAC assemblies
Use `-r:` compiler option to reference GAC assemblies:
```C#
#!/usr/bin/csexec -r:System.Windows.Forms.dll -r:System.Drawing.dllusing System;
using System.Drawing;
using System.Windows.Forms;public class Program
{
public static void Main (string [] args)
{
MessageBox.Show ("Hello, world!");
}
}
```## Reference file assemblies
`csexec` allow reference file assemblies from the `~/.config/csharp` directory (same as with Mono C# shell).
Note that you still need to reference them with `-r:` compiler option to be able to use their features in the code.```C#
#!/usr/bin/csexec -r:MyLibrary.dllusing System;
using MyLibrary;public class Program
{
public static void Main (string [] args)
{
var myObject = new MyClass ();
Console.WriteLine (myObject);
}
}
```## Template scripts
See template scripts in the `templates` directory.
## R7.Scripting
`csexec` works better along with [R7.Scripting](https://github.com/roman-yagodin/R7.Scripting) library,
which provides various components to simpify C# scripting and easily integrate your scripts with
*Nautilus* / *Nemo* / *Caja* file managers.