Roslyn: Run/Inline Other Script
-
31 Januari 2012 15:12Hi, is there a way to "include" ("require", "execute", "inline" etc.) another scipt from a script (csx file)? I think of a similar functionality as e.g. in PHP.
- Dipindahkan oleh Robert BreitenhoferMicrosoft Contingent Staff 02 Februari 2012 16:27 Microsoft "Roslyn" CTP (From:Visual Studio)
Semua Balasan
-
02 Februari 2012 14:04
Siehe:
http://www.developerfusion.com/article/84414/scripting-with-c/
Martin Richter -- MVP for VC++ [Germany] -- http://blog.m-ri.de -
02 Februari 2012 21:10Pemilik
Hi - As far as I am aware there is no way to "include" / "reference" / "execute" one CSX file from within another in the CTP.
You can execute scripts in the command prompt using rcsi.exe in the CTP e.g. rcsi.exe "Script1.csx" "Script2.csx". (rcsi.exe is present under "Program Files (x86)\Microsoft Codename Roslyn CTP\Binaries".) The order of execution of the CSX files will be the order specified on the command line. You may also find Bill's comments about csx files and rcsi.exe on this post to be of interest.
You can also execute any CSX file from within the C# Interactive window using the #load command. However, #load is a REPL command and not part of the C# language so it can't be used within a CSX file.
We have considered / discussed the scenario that you describe (i.e. ability to "include" one CSX file from within another) in the past and I beleive it is something that is on our radar although there are no promises we can make at this point :)
Shyam Namboodiripad | Software Development Engineer in Test | Roslyn Compilers Team -
02 Februari 2012 21:30Pemilik
Hi. First let me say that Shyam's answer is great, and I'm assuming the key part for you is that you can add more than one .csx or .cs file to the csi.exe command line. I wanted to ask what your scenario is, or were you just curious? My guess is that you're looking for the script file to be self-contained so that a user only needs to know one file name to invoke it? If you have a need for this support, then I'd like to hear about it!
I did play around with csi.exe and wrote my own version that allows #load "some.csx", and it has the semantics of ordering all the files (same way python or php would), sort of a depth first, post order execution. I could share that code as an example, but I'm not sure if its current state works with the CTP bits (it also uses some internal code for parsing the command line). I could just snip the part that collects the .csx files in the correct order, but I use a syntaxwalker whose shape may have changed since the CTP. Anyway, all I did was look for erroneous directive trivia at the top of the file (because #load is an error in the language), then remove the #load line from teh syntax tree, collect all the syntax trees in the right order, then pass them to a compilation unit.
Bill
- Ditandai sebagai Jawaban oleh billchi_msOwner 25 Februari 2012 0:22