AngleSharp / AngleSharp.Css

:angel: Library to enable support for cascading stylesheets in AngleSharp.

Home Page:https://anglesharp.github.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

AngleSharp.Css 1.0.0-beta.139: Dependencies in csproj and nuspec do not match - leads to error in .Net Framework and .Net (Core)

GruberMarkus opened this issue · comments

Prerequisites

  • Can you reproduce the problem in a MWE?
  • Are you running the latest version of AngleSharp.Css?
  • Did you check the FAQs to see if that helps you?
  • Are you reporting to the correct repository? (there are multiple AngleSharp libraries, e.g., AngleSharp.Xml for Xml support)
  • Did you perform a search in the issues?

Description

AngleSharp.Css 1.0.0-beta.139
Nuget downloads the wrong AngleSharp dependency, likely because of the following differing configurations:

  • nuspec file: <dependency id="AngleSharp" version="[1.0.0, 2.0.0)" />
  • csproj file: <PackageReference Include="AngleSharp" Version="1.1.0" />

With default settings (-DependencyVersion Lowest), NuGet downloads AngleSharp 1.0.0. This leads to problems in .Net Framework and .Net (Core), becauce AngleSharp.Css requires AngleSharp 1.1.0, not 1.0.0.

With -DependencyVersion Lowest, NuGet downloads AngleSharp 1.2.0-beta.410. This is not problem in .Net (Core), as it seems to automatically use the newer release. On .Net Framework, this leads to the following error:
Could not load file or assembly 'AngleSharp, Version=1.1.0.0, Culture=neutral, PublicKeyToken=e83494dcdc6d31ea' or one of its dependencies. The system cannot find the file specified.

Steps to Reproduce

  1. nuget.exe install AngleSharp.Css -Framework net461 -Version "1.0.0-beta.139" -OutputDirectory ".\AngleSharp.Css_with-deps_net461" -NoHttpCache -DirectDownload -Verbosity quiet -DependencyVersion lowest
    or
    nuget.exe install AngleSharp.Css -Framework net461 -Version "1.0.0-beta.139" -OutputDirectory ".\AngleSharp.Css_with-deps_net461" -NoHttpCache -DirectDownload -Verbosity quiet -DependencyVersion highest
  2. Extract all net461 DLLs and place them in the same folder
  3. Import AngleSharp.Css.dll in .Net Framework,not in .Net (Core)
    System.Reflection.Assembly.LoadFrom("path-to-anglesharp.css.dll")
    or in PowerShell 5: import-module -Path "path-to-anglesharp.css.dll"
  4. As NuGet download AngleSharp 1.0.0 or 1.2.*, AngleSharp.Css can not load version 1.1.0, resulting in the error: Could not load file or assembly 'AngleSharp, Version=1.1.0.0, Culture=neutral, PublicKeyToken=e83494dcdc6d31ea' or one of its dependencies. The system cannot find the file specified.

Expected Behavior

The NuGet package is configured to download the correct version of the AngleSharp dependency.

Actual Behavior

The NuGet package seems not to be configured to download the correct version of the AngleSharp dependency, and AngleSharp.Css on .Net Framework (not .Net (Core)) is bound to only use AngleSharp 1.1.0.

Possible Solution / Known Workarounds

Adopt the nuspec file, and maybe also a binding redirect (dotnet/announcements#31).

AngleSharp.Css requires AngleSharp 1.1.0

I don't think this should be the way. I use both together (1.0.0 and 1.0.0 beta). Sure you are not having a bad config (app config that redirects)? There should not be a binary dependency on a specific version.

The NuGet package is configured to download the correct version of the AngleSharp dependency.

This is wrong. It should work as a peer dependency, where in failure / absence nuget decides something - but you can override it by explicitly installing a version in the provided range. The range is intentional and will stay.

Reproducing downloading the wrong AngleSharp.dll version with a C# project:

AngleSharp.Css-test.cs

using System;

using AngleSharp;
using AngleSharp.Css;
using AngleSharp.Css.Dom;
using AngleSharp.Css.Parser;
using AngleSharp.Dom;
using AngleSharp.Html;
using AngleSharp.Html.Dom;
using AngleSharp.Html.Parser;

public class Program
{
	public static void Main()
	{
		var ctx = BrowsingContext.New(Configuration.Default.WithCss());
		var htmlParser = ctx.GetService<IHtmlParser>();
		var doc = htmlParser.ParseDocument("<html><body><div>Div text <span>sp<em>an te</em>xt</span></div><p>Paragraph<p>Another paragraph</body></html>");
		Console.WriteLine(doc.Body.GetInnerText());
	}
}

AngleSharp.Css-Test.csproj

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <AssemblySearchPaths>$(AssemblySearchPaths);{GAC}</AssemblySearchPaths>
    <TargetFrameworks>net461</TargetFrameworks>
    <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
    <ImplicitUsings>enable</ImplicitUsings>
    <LangVersion>latest</LangVersion>
    <Nullable>enable</Nullable>
    <SignAssembly>False</SignAssembly>
    <EnableNETAnalyzers>True</EnableNETAnalyzers>
    <AnalysisLevel>latest</AnalysisLevel>
    <OutputType>Library</OutputType>
    <AssemblyVersion></AssemblyVersion>
    <InformationalVersion></InformationalVersion>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="AngleSharp.Css" Version="1.0.0-beta.139" />
  </ItemGroup>

</Project>

dotnet restore runs without error or warnings, but download AngleSharp 1.0.0 because of the NuGet file. Then, dotnet build fails because AngleSharp.Css references AngleSharp 1.1.0:

CSC : error CS1705: Assembly 'AngleSharp.Css' with identity 'AngleSharp.Css, Version=1.0.0.0, Culture=neutral, PublicKeyToken= 
e83494dcdc6d31ea' uses 'AngleSharp, Version=1.1.0.0, Culture=neutral, PublicKeyToken=e83494dcdc6d31ea' which has a higher vers 
ion than referenced assembly 'AngleSharp' with identity 'AngleSharp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=e83494dc 
dc6d31ea' [C:\dev\AngleSharp.Css-Test\AngleSharp.Css-Test.csproj::TargetFramework=net461]

Let's add <PackageReference Include="AngleSharp" Version="1.1.0" /> to the csproj file:

Build succeeded.

It seems that the lower version bound for AngleSharp in the nuspec file of AngleSharp.Css is set too low (1.0.0 should be 1.1.0)