Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CS-Script - How Can I Run a '.cs' File Like A Standard Windows Executable? [closed]

I have recently installed CS-Script, a scripting system for C# (as well as VB.NET, C++/CLI and J#).

CS-Script allows you to write a program in standard C# syntax (or in other languages supported by CS-Script) and run it without first compiling it to an executable! In this way, CS-Script offers the benefits of Windows Script Host (WSH) and other scripting frameworks and languages.

By default, when you double-click a .cs file, CS-Script is configured to to open it with Notepad. Instead, I actually wanted to change this so that double-clicking the .cs file would run the script. I was able to make this change by running the CS-Script configuration program css_config.exe, and under Open (double-click action), selecting <Run>.

Now, a question: There is one more thing I want to do--I'd like to be able to put a .cs file somewhere in my system path and run it like any other standard Windows executable. (For example, .exe, .bat and .cmd files.) Is this is possible?

like image 477
DavidRR Avatar asked Dec 11 '13 18:12

DavidRR


People also ask

Can I use C# for scripting?

C# scripting is a tool for testing out your C# and . NET snippets without the effort of creating multiple unit testing or console projects. It provides a lightweight option for quickly coding up a LINQ aggregate method call on the command line, checking the .

How do I make a CS script?

You can create a CS-Script command environment by just opening the Developer Command Prompt for Visual Studio and typing CSI. Once the window has re-displayed the command prompt, you can start entering and executing CS-Script.


Video Answer


1 Answers

Yes, this is possible! You simply need to tell Windows that a .cs file is an executable file. To accomplish this, all that you need to do is add the .cs file extension to your PATHEXT environment variable.

For example, here's what PATHEXT looks like on my Windows 7 system after I have appended the .cs extension:

PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC;.CS
                                                             ^^^^

You may also want to eliminate the banner that CS-Script outputs when you run your script. To eliminate the banner, run css_config.exe, and under Open (double-click action), add the /nl command line option. For example, if you have installed CS-Script at C:\cs-script, your modified command line will look like this:

"C:\cs-script\cscs.exe" /nl "%1" %*
                        ^^^
like image 82
DavidRR Avatar answered Oct 04 '22 09:10

DavidRR