1
votes

I am working to move out NuGet references from using the packages.json format to PackageReferences. I have an issue with NuGet package compatibility: The package supports an older version of the .NET Framework.

This, using the packages.json format, works just fine.

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="MarkdownDeep.NET-Signed" version="1.5" targetFramework="net461" />
</packages>

<Reference Include="MarkdownDeep, Version=1.5.5082.29984, Culture=neutral, PublicKeyToken=65640b2d9fe5ac0e, processorArchitecture=MSIL">
  <HintPath>..\..\packages\MarkdownDeep.NET-Signed.1.5\lib\.NetFramework 3.5\MarkdownDeep.dll</HintPath>
  <Private>True</Private>
</Reference>

However, replacing this with a PackageReference instruction in the .csproj file results in the error below:

<PackageReference Include="MarkdownDeep.NET-Signed">
  <Version>1.5</Version>
</PackageReference>

"C:\Source\WebApp.csproj" (Restore target) (1) -> (Restore target) -> C:\Source\WebApp.csproj : error NU1202: Package MarkdownDeep.NET-Signed 1.5.0 is not compatible with net472 (.NETFramework,Version=v4.7.2). Package MarkdownDeep.NET-Signed 1.5.0 supports: netframework35 (.NetFramework 3.5,Version=v0.0)

Note that the current target framework in both cases is the same, v4.7.2.

Are there any additional instruction to add to the <PackageReference> node that will allow me to indicate that it is OK for this to target .NET Framework 3.5?

Note: There's some good info in Package references (PackageReference) in project files, but it seems it only deals with TargetFramework as a variable to conditionally add references. I don't think I have a mix of .NET Framework versions to deal with - it's just v4.7.2 all the way.

1

1 Answers

1
votes

I've only been working on the NuGet team for a few months, so I don't consider myself an expert in all thing NuGet, but I would suggest that the MarkdownDeep.NET-Signed package might not be authored correctly.

From your sample you copied from the csproj using packages.config, you can see the package contains a lib\.NetFramework 3.5\ folder. However, NuGet packages usually use the short form lib\net35\. From a quick test of creating a console app, referencing the NuGet.Frameworks package and then using NuGetFramework.Parse(".NetFramework 3.5"), the resulting object has an "unsupported" framework. NuGet Package Explorer (available in the Microsoft Store) is a 3rd party app, so not guaranteed to work the same way that NuGet does in VS, but it also shows the .NetFramework 3.5 as "Unrecognized framework" lending further evidence that it could be an incorrectly authored package.

Given that the package does not appear to be correct, it is valid for NuGet to fail restore with PackageReference since NuGet is responsible for selecting assets from the package that are compatible with your project. I don't know why installing the package in a packages.config project works though.

If you're just looking for a .NET markdown parser, from what I can tell markdig is the most popular and still maintained package available on nuget.org.