|
Toolsack DotNet Script HostThis is an introduction to the DotNet Script Host from Toolsack Software. The DNSH is based on the Windows Script Host (WSH) from Microsoft. It allows you to run plain text files containing code in .NET languages, currently C# and JScript.
InstallationTo install the DNSH, run the msi file from Toolsack Software. Note that you will need the .NET runtime which is freely available from Microsoft. This can be found at http://windowsupdate.microsoft.com/. Hello WorldText files with a .ns extension are considered a DotNet script. Double clicking the file will run the DotNet Host which will compile and execute the script.
To start with, create a new text file, insert the following text and save.
System.Windows.Forms.MessageBox.Show("Hello World.");
Rename the file to first.ns and then double click the file. A dialog box should appear with the Hello world message.
Hello World in C#Different languages can be used by setting the language directive as shown below:
@ Script Language="csharp"
System.Windows.Forms.MessageBox.Show("Hello Word.");
Including namespacesOf course the original script could be written better like this:
import System.Windows.Forms;
MessageBox.Show("Hello World.");
Note that the System namespace is always imported.
Including AssembliesThe Assembly directive allows you to include other assemblies and is used as shown:
@ Assembly Name="System.Xml.dll"
var xdoc: System.Xml.XmlDocument;
xdoc = new System.Xml.XmlDocument();
ClassesThe scripts can include your own types, just like any other .NET code eg: import System.Windows.Forms;
var a: FirstClass;
a = new FirstClass();
a.func1();
class FirstClass
{
function func1():void
{
MessageBox.Show("You are in FirstClass::func1");
}
}
TimeoutThe timeout directive will abort a thread after the number of seconds has expired eg:
@ Script timeout = "2"
import System.Threading;
System.Threading.Thread.Sleep(5000);
System.Windows.Forms.MessageBox.Show("Hello World.");
EditorThe script comes with its own editor. Either start this from the start menu or right click on a .ns file and choose the edit command.
The editor is a simple text editor like notepad, but lists errors in the bottom pane, and it can run scripts without saving the file.
FinishThe Toolsack DotNet Script Host is a great way to write scripts for the .NET platform.
The next version will be even better, in the meantime, if you have any problems or suggestions write to support@toolsack.com.
|