c# - 从程序集 c# 引用 .dll

标签 c# unity3d .net-assembly

我正在开发一个语言翻译程序,我从离线获取信息。我正在使用 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 放在我的脚本所在的文件夹中来修复此错误。这摆脱了错误。感谢您的所有帮助!

关于c# - 从程序集 c# 引用 .dll,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12821320/

相关文章:

c# - 将字符串解析为 Unity3D 中的代码 (C#)

c# - 从其他项目打开 wpf 窗口

c# - 获取程序集的全名

c# - 如何在不使用 EF 的情况下使用 Breeze 保存更改?

c# - 从 C# 中的 Object 继承是多余的吗?

unity3d - 如何在 Unity 上结合 Cardboard VR + Vuforia AR 插件?

c# - Unity3D 中 WebCamTexture 的色度键着色器

c# - 为什么 Dictionary<TKey, TValue>.KeyCollection 类没有自己的 Contains 方法?

C#:更改事件目录用户密码时出现代码错误

asp.net - 发布到 Azure 程序集 Microsoft.Owin 后无法加载