简体   繁体   English

如何在Visual Studio Code中添加对HTMLAgilityPack的引用

[英]How do I add a reference to HTMLAgilityPack in Visual Studio Code

I'm using Visual Studio Code and .NET core on OSX. 我在OSX上使用Visual Studio Code和.NET Core。

HtmlAgilityPack.NetCore.1.5.0.1 has been installed to the project folder. HtmlAgilityPack.NetCore.1.5.0.1已安装到项目文件夹。 All of my project files, HTMLAgilityPack.NetCore.1.5.0.1 and all of the dependencies are visible in the explorer pain. 我的所有项目文件HTMLAgilityPack.NetCore.1.5.0.1和所有依赖项都可以在资源管理器中看到。 Yet I cannot create a reference to any HtmlAgilityPack assemblies. 但是我无法创建对任何HtmlAgilityPack程序集的引用。

The code is simple. 代码很简单。 It compiles and runs. 它编译并运行。

namespace ConsoleApplication
{
    using System;
    using System.Text.RegularExpressions;
    using System.Linq;

    public class Program
    {
        public static void Main(string[] args)
        {
            Console.WriteLine("Hello, world");
        }
    }
}

Is there a step beyond installing the nuget package that I need to perform to get this to work? 除了安装我需要执行的nuget软件包之外,还有其他步骤吗?

Unless I'm misunderstanding your question, this should be very straight forward. 除非我误解了您的问题,否则这应该很简单。 All you need to do is: 您需要做的只是:

1: Add the nuget package into your project.json file like so, then run dotnet restore in the same directory as your project.json file to restore your newly added package. 1:像这样将nuget包添加到project.json文件中,然后在与project.json文件相同的目录中运行dotnet restore来还原新添加的包。

...
},
"dependencies": {
    "HtmlAgilityPack.NetCore": "1.5.0.1"
},
"frameworks": {
...

2: Add the following using statement to the top of your code. 2:将以下using语句添加到代码顶部。

using HtmlAgilityPack;

This works for me: 这对我有用:

namespace ConsoleApplication
{
    using System;
    using HtmlAgilityPack;

    public class Program
    {
        public static void Main(string[] args)
        {
            HtmlDocument doc = new HtmlDocument();

            Console.WriteLine("Hello, world");
        }
    }
}

Note: As you're using Visual Studio Code on OSX, you can reference a class and then press the shortcut CMD + . 注意:在OSX上使用Visual Studio Code时,可以引用一个类,然后按快捷键CMD + . to bring up Visual Studio Code's tool window and automatically import your missing using statement. 调出Visual Studio Code的工具窗口,并自动导入您丢失的using语句。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM