2011-01-09 36 views
0

我將Antlr3.StringTemplate.dll和Antlr3.Runtime.dll從http://www.stringtemplate.org/複製到cs-script/lib目錄(http://www.csscript.net/)並執行下面的代碼,但它說它無法找到Antlr的程序集爲什麼?我的編號如下如何用StringTemplate運行cs-script(c#腳本)?

//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", "Micheal"); 
helloAgain.SetAttribute("friends", "Marq"); 

Console.Out.WriteLine(helloAgain.ToString()); 
    } 
} 
+0

這是真的嗎?或者它是否說*「......或者它的一個依賴關係......」*?我會建議使用融合日誌並查看是否缺少任何依賴關係。 – 2011-01-09 20:47:30

回答

1

該錯誤表示CS腳本無法解析Antlr3。*。dll程序集。

您需要指示腳本引擎可能位於這些程序集的位置,如果您不這樣做,CS腳本將只在GAC,本地目錄(腳本所在的位置)以及[cs-script ] \ lib中。

您有幾種選擇來解決這個問題:

  • 您可以指定使用絕對路徑
  • 組件探測目錄添加到CS-腳本全局設置,或直接到你的腳本。
  • 在GAC中註冊Antrl。

看看AddingSearchDirs和www.csscript.net/help/Using_.NET_assemblies.html,這會幫助你開始。

+0

終於這是由於從官方網頁下載包不起作用,從其他地方下載更好。 – user310291 2011-01-09 23:48:04