What is the best way to use scriptcs by leverage visual studio for optional editing and debugging.

330 views
Skip to first unread message

Kenneth Kasajian

unread,
Feb 26, 2015, 1:51:40 AM2/26/15
to scri...@googlegroups.com
Without scriptcs, I could use Visual Studio and create a console app to write the various scripts that I need to.    At times, using Visual Studio has some advantages -- It's a nice editor, you can use tools like resharper, use the integrated unit testing, code coverage, etc and other tools.   Although that may seem like a reasonable approach during initial development, once I'm done, it's kind of a pain to have to launch Visual Studio again every time I want to make a change to the code.

Imagine the workflow.   I'm at the command prompt, and I want to run a C# script.   Yeah, I see the source, but I can't execute it.   If I just did a git clone/pull, I have to launch Visual Studio and compile the code just to run it.   Why can't I just run the C# file directly?

Well that's where scriptcs comes in.

So here's what I want.  I want the best of both worlds.

I want to be able to use Visual Studio and all the built-in tools *if* I choose to.   But if I'm at the command prompt, and Visual Studio isn't running, I shouldn't be required to.   I should be able to just run the C# file directly using scriptcs.   This is especially useful for others in my team who are just users of the code.   If they get the latest changes to the script, they shouldn't have to rebuild it.

Has anyone tried setting up such a development environment?

I've thought about it a little, and here are my initial thoughts.
1.  I would put most of the logic of the script in separate C# files, in classes, using C# syntax that's compatible with both scriptcs and regular C#.
2.  I would have a single .csx file that #loads the other class files.
3.  I'd have a Visual Studio Class Library file which includes each of the class files, but not the .csx file.   The project builds a DLL.
4.  For debugging, I point to scriptcs.exe -debug and pass in the .csx file.
5.  When the debugger is started, scriptcs.exe is launched and it will load the .csx files and each of the associated class files being loaded #load.   In fact, the actual assembly created by Visual Studio (in bin\debug) won't be the one being debugged.
6.  I'll need to be able to support command arguments to the script.   And from Visual Studio, I should be able to add the arguments to the debugger project settings.   
7.  The .dll in bin\debug is really only used during unit testing.

I haven't done of this so I really haven't vetted this out.   I'm really only posting this to get a discussion going and to get further feedback.
If this approach makes sense, and I use it, I'll write a proper blog on what actually we ended up with.

Thank you.

Adam Ralph

unread,
Mar 1, 2015, 12:23:28 PM3/1/15
to scri...@googlegroups.com
Hi Kenneth,

As far as I can see, what you describe should be possible. It's not something I've tried, but I'd be very interested to know how you get on. A blog post sounds great!

If you get stuck please don't hesitate to shout for help. Either here or https://jabbr.net/#/rooms/scriptcs are good places to ask.

Glenn Block

unread,
Mar 1, 2015, 2:35:10 PM3/1/15
to Adam Ralph, scri...@googlegroups.com
The main issue is that namespaces are not supported.

You might be able to have that work anyway as I don't think they are required,, but you will have to test.

Adam Ralph

unread,
Mar 1, 2015, 3:31:13 PM3/1/15
to scri...@googlegroups.com, ad...@adamralph.com
Good point @Glenn Block.

You can indeed write the C# classes in the .cs files without namespaces and the resulting assembly will be perfectly functional, albeit a little odd looking. Whether it is acceptable, I guess depends on the intended use of the assembly.
Reply all
Reply to author
Forward
0 new messages