I am using Neovim on Windows 11 and trying to experiment with some webpage scraping in C#. I thought it would be a good idea to use HtmlAgilityPack as a reference to make this task easier. For some reason, despite having the .dll file for HtmlAgilityPack in the bin of my project, and a reference in my .csproj file, I get the error when compiling:
"error CS0246: the type or namespace name 'HtmlAgilityPack' could not be found (are you missing a using directive or an assembly reference?)"
Note: This is my first attempt to write a program in C# using Neovim. In the past I have used an IDE like Visual Studio.
I have tried deleting and re-adding the package. I've tried closing Neovim and recompiling the program in terminal. I have tried putting the "using" statement inside of the namespace to no avail.
Program.cs
using HtmlAgilityPack;
namespace SubstackFollowerTool
{
class SubstackFollowerTool
{
static void Main()
{
var url = "https://url.com";
var web = new HtmlWeb();
var doc = web.Load(url);
// Assuming names are in <span> tags with class "name"
var nameNodes = doc.DocumentNode.SelectNodes("<span>");
if (nameNodes != null)
{
foreach (var nameNode in nameNodes)
{
Console.WriteLine(nameNode.InnerText);
}
}
}
}
}
SubstackFollowerTool.csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.Net.Http" Version="4.3.4" />
<PackageReference Include="HtmlAgilityPack" Version="1.11.59" />
</ItemGroup>
</Project>
SubstackFollowerTool.sln
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.5.002.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SubstackFollowerTool", "SubstackFollowerTool.csproj", "{07EB57D3-0AA2-4096-8105-934C9A7ECBEB}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{07EB57D3-0AA2-4096-8105-934C9A7ECBEB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{07EB57D3-0AA2-4096-8105-934C9A7ECBEB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{07EB57D3-0AA2-4096-8105-934C9A7ECBEB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{07EB57D3-0AA2-4096-8105-934C9A7ECBEB}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {1A42E2A5-2435-49E6-A7D0-777AF3DA44CE}
EndGlobalSection
EndGlobal
Terminal Log:
Microsoft Windows [Version 10.0.22631.3155]
C:\Users\charl\Desktop\SubstackFollowerTool>csc Program.cs
Microsoft (R) Visual C# Compiler version 4.8.9032.0
for C# 5
Copyright (C) Microsoft Corporation. All rights reserved.
This compiler is provided as part of the Microsoft (R) .NET Framework, but only supports language versions up to C# 5, which is no longer the latest version. For compilers that support newer versions of the C
# programming language, see http://go.microsoft.com/fwlink/?LinkID=533240
Program.cs(1,7): error CS0246: The type or namespace name 'HtmlAgilityPack' could not be found (are you missing a using directive or an assembly reference?)
C:\Users\charl\Desktop\SubstackFollowerTool>
Thanks for the help in advance,