73

I've heard of .cs files but never of .csx files. Google searches led me to CSX corporation and other unwanted bodies. Can someone provide a terse description of what a CSX file is, and perhaps the main differences between CSX and CS?

Marc Climent
  • 9,006
  • 2
  • 47
  • 54
Robin Rodricks
  • 99,791
  • 133
  • 372
  • 575

4 Answers4

80

It is a C# Script File introduced with Roslyn:

C# Script File (.csx) Editing Support: The CTP introduces a concept of a C# Script File. You can create a .csx file [...]

[What is Roslyn? .NET Compiler Platform, also known by its nickname Roslyn, is a set of open-source compilers and code analysis APIs for C# and Visual Basic .NET languages from Microsoft.]

You don't have to have everything in a class and method, a csx file is like it's own method, and everything in the file will be executed on start. It also supports some additional directives (like #load to load another script).

The Scripting Api provided in Roslyn, while being promising, has some severe flaws:

Scripting APIs require desktop .NET Framework 4.6+.

  • It means it was not cross-platform. (but with .NET Core, now it should be).
  • The syntax of C# is not really script oriented (too verbose)
  • The directives available while mandatory are not sufficient to cover the broad scope of a CLI (like powershell). For exemple, there is no cd, alias, pwd, ls, exec or the like.

There are several scripting engines which are based on it (or on the underneath Roslyn) or at least on the same format, while providing more advanced directives. So, it means a csx file should run on one of the following:

Beware, even if they share a common base, they are not cross-compatible, since there is no standard on the extensions they implement.

NealWalters
  • 14,090
  • 34
  • 109
  • 199
Juri Robl
  • 5,044
  • 2
  • 26
  • 40
22

Right now (2019), .csx files are also used in the online code editor provided by Microsoft.

For example, you can develop an application entirely from the browser and continuously deploy it from there. Here's an example bot created from the Azure Portal and written in CSX via browser:

enter image description here

3

It is a script file used by ScriptCS to allow you to create executables without having to create a project file.

John Koerner
  • 35,668
  • 7
  • 74
  • 128
-1

It is Scriptcs file http://scriptcs.net/ . It can executed with scriptcs compiler

satish
  • 2,311
  • 2
  • 21
  • 36