NuGet / Home

Repo for NuGet Client issues
Other
1.5k stars 252 forks source link

MSB4018 - "ResolvePackageDependencies" task fails with "Invalid framework version '2.0/win'" #13942

Open jbparker opened 1 week ago

jbparker commented 1 week ago

NuGet Product Used

MSBuild.exe

Product Version

MSBuild via VS 2022 17.12.0

Worked before?

Worked in VS 2022 17.11.5

Impact

It's more difficult to complete my work

Repro Steps & Context

The error is being emitted for PackageReference projects with the following attributes:

<TargetFramework>netstandard2.0</TargetFramework>
<RuntimeIdentifiers>win</RuntimeIdentifiers>

Assumedly, this is where the 2.0/win comes from. There are many dozens of dependencies (package, product, etc), so determining how to singularly reproduce is exceedingly difficult.

Building and running the project itself does not seem to be impacted, but the error displaying is causing much confusion with developers that have upgraded VS on our team.

Adding <NuGetAuditMode>direct</NuGetAuditMode> to Directory.Build.props based on the auditing mode change made as part of .NET 9 removes the error from the Error List.

Verbose Logs

I can't get additional logs to show up in VS, but what shows in Error List is:

Severity: Error
Code: MSB4018
Description: The "ResolvePackageDependencies" task failed unexpectedly.
System.ArgumentException: Invalid framework version '2.0/win'.
   at NuGet.Frameworks.NuGetFramework.ParseFrameworkNameParts(IFrameworkNameProvider mappings, String[] parts, String& framework, Version& version, String& profile)
   at NuGet.Frameworks.NuGetFramework.ParseFrameworkName(String frameworkName, IFrameworkNameProvider mappings)
   at Microsoft.NET.Build.Tasks.ResolvePackageDependencies.<GetPackageAndFileDefinitions>b__44_5(String tg)
   at System.Linq.Enumerable.WhereSelectListIterator`2.MoveNext()
   at System.Linq.Enumerable.Contains[TSource](IEnumerable`1 source, TSource value, IEqualityComparer`1 comparer)
   at System.Linq.Enumerable.WhereListIterator`1.MoveNext()
   at System.Linq.Enumerable.Any[TSource](IEnumerable`1 source)
   at Microsoft.NET.Build.Tasks.ResolvePackageDependencies.<GetPackageAndFileDefinitions>g__GetPackageDiagnosticLevel|44_0(LockFileLibrary package)
   at Microsoft.NET.Build.Tasks.ResolvePackageDependencies.GetPackageAndFileDefinitions()
   at Microsoft.NET.Build.Tasks.TaskBase.Execute()
   at Microsoft.Build.BackEnd.TaskExecutionHost.Execute()
   at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext()
File: C:\Program Files\dotnet\sdk\9.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets
Line: 196
zivkan commented 1 week ago

The relevant code is in the dotnet/sdk repo, and is very likely related to the code I added to enable bubbling up warning overlay icons from the direct package to the dependencies node in VS's solution explorer: