How to run cs-script (c# script) with StringTemplate?
I copied Antlr3.StringTemplate.dll and Antlr3.Runtime.dll from http://www.stringtemplate.org/ to cs-script/lib directory ( http://www.csscript.net/ ) and execute the code below but it says it cannot find the assemblies of Antlr why ? My prog below
//css_reference Antlr3.Runtime.dll;
//css_reference Antlr3.StringTemplate.dll;
using System;
using Antlr.StringTemplate;
using Antlr.StringTemplate.Language;
using System.Windows.Forms;
class Script
{
static public void Main(string[] args)
{
StringTemplateGroup group = new StringTemplateGroup("myGroup", @"C:\Tutorials\stringtemplate", typeof(DefaultTemplateLexer));
StringTemplate helloAgain = group.GetInstanceOf("homepage");
helloAgain.SetAttribute("title", "Welcome To StringTemplate");
helloAgain.SetAttribute("name", "World");
helloAgain.SetAttribute("friends", "Terence");
helloAgain.SetAttribute("friends", "Kunle");
helloAgain.SetAttribute("friends", "Mic开发者_Go百科heal");
helloAgain.SetAttribute("friends", "Marq");
Console.Out.WriteLine(helloAgain.ToString());
}
}
The error means that CS-Script cannot resolve Antlr3.*.dll assemblies.
You need to instruct the script engine where these assemblies may be located and if you do not do this CS-Script will look only in the GAC, your local directory (where the script is) and in the [cs-script]\Lib.
You have a few options to solve the problem:
- You can specify assemblies with the absolute path
- Add probing directories to the CS-Script global settings or directly to your script.
- Register Antrl in GAC.
Have a look at AddingSearchDirs and www.csscript.net/help/Using_.NET_assemblies.html, this will help you to start.
精彩评论