NuGet / Home

Repo for NuGet Client issues
Other
1.49k stars 250 forks source link

[Bug]: Nuget.Client does not work for .NETFramework < 4.7.2 #11335

Open gabriela-lungu-uip opened 2 years ago

gabriela-lungu-uip commented 2 years ago

NuGet Product Used

MSBuild.exe

Product Version

NuGet.Frameworks package 5.11.0

Worked before?

NuGet.Frameworks package 5.8.0

Impact

I'm unable to use this version

Repro Steps & Context

Repro Steps: .NETFramework4.6.1 Console Application:

    using NuGet.Commands;
    using NuGet.Frameworks;
    using System.Collections.Generic;
    class Program
    {
        static void Main()
        {
            AssetTargetFallbackUtility.GetFallbackFramework(NuGetFramework.AnyFramework,
                new List<NuGetFramework>() { NuGetFramework.AnyFramework },
                new List<NuGetFramework>() { NuGetFramework.AnyFramework });
        }
    }

throws:

System.MissingMethodException
  HResult=0x80131513
  Message=Method not found: 'Void NuGet.Frameworks.FallbackFramework..ctor(NuGet.Frameworks.NuGetFramework, System.Collections.Generic.IReadOnlyList`1<NuGet.Frameworks.NuGetFramework>)'.
  Source=NuGet.Commands
  StackTrace:
   at NuGet.Commands.AssetTargetFallbackUtility.GetFallbackFramework(NuGetFramework projectFramework, IEnumerable`1 packageTargetFallback, IEnumerable`1 assetTargetFallback)
   at Nuget5._11Issue.Program.Main() in ...\Program.cs:line 10

Context: I have encountered this problem while using Restore from Nuget.Commands after upgrading to version=5.11.0 from 5.8

Investigation: Nuget.Frameworks 5.11 targets .NETFramework 4.0, .NETFramework 4.7.2 and .NETStandard 2.0. A project that targets .NET461 will use the Nuget.Frameworks for .NETFramework 4.0 because it's the closest version. On .NETFramework 4.0 the reported missing method is indeed missing. Nuget.Frameworks 5.8 targets also .NETFramework 4.5 which for a NET461 project would be the closest version and on this version the method is not missing.

Verbose Logs

No response

dominoFire commented 2 years ago

Reproduced.

By looking at code, we use IList instead of IReadOnlyList when target framework is net40:

https://github.com/NuGet/NuGet.Client/blob/c14b85a00c03933c708c7d38fefeda9898a21488/src/NuGet.Core/NuGet.Frameworks/FallbackFramework.cs#L35

Would you be able to use a newer target framework ?