我正在开发一个语言翻译程序,我从离线获取信息。我正在使用 Unity 游戏引擎,它使用 Assembly 作为其 IDE。到目前为止,下面是我的代码。
class Dictionary
{
public string Translate(string input, string languagePair, Encoding encoding)
{
string url = String.Format("http://www.google.com/translate_t?hl=en&ie=UTF8&text={0}&langpair={1}", input, languagePair);
string result = String.Empty;
using (WebClient webClient = new WebClient())
{
webClient.Encoding = encoding;
result = webClient.DownloadString(url);
}
HtmlDocument doc = new HtmlDocument();
doc.LoadHtml(result);
return doc.DocumentNode.SelectSingleNode("//textarea[@name='utrans']").InnerText;
}
}
但是,在编译时,我收到错误:
Assets/DictionarySp.cs(8,7): error CS0246: The type or namespace name `HtmlAgilityPack' could not be found. Are you missing a using directive or an assembly reference?
开始研究,听说HtmlAgilityPack是第三方软件,必须要引用.dll。我下载了 VisualStudio2010,还有 NuGet。在 Visual Studio 中,我单击“管理 NuGet 包”并安装了 HtmlAgilityPack。在 Visual Studio 内部,错误消失了,但是当我尝试在 Assembly 中打开文件时,我仍然收到无法找到命名空间 HtmlAgilityPack 的错误。我使用的是 Unity 游戏引擎,所以我必须从 VisualStudio 文件中取出文件并将其放在不同的文件夹中。是否缺少某些步骤,或者我是否需要在程序集中执行某些操作以引用 HtmlAgilityPack dll?任何帮助将不胜感激。
请您参考如下方法:
在像 Austin 和 Shakir 所说的那样引用 HtmlAgilityPakc.dll 之后,我仍然无法让错误生效。我通过不仅引用 HtmlAgilityPack.dll,而且将 HtmlAgilityPack.dll 放在我的脚本所在的文件夹中来修复此错误。这摆脱了错误。感谢您的所有帮助!
