简体   繁体   中英

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

I'm using Visual Studio Code and .NET core on OSX.

HtmlAgilityPack.NetCore.1.5.0.1 has been installed to the project folder. All of my project files, HTMLAgilityPack.NetCore.1.5.0.1 and all of the dependencies are visible in the explorer pain. Yet I cannot create a reference to any HtmlAgilityPack assemblies.

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?

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.

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

2: Add the following using statement to the top of your code.

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 + . to bring up Visual Studio Code's tool window and automatically import your missing using statement.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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