Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: NuGet 6.2 incompatible with lock file from NuGet 6.1 - NU1101: Unable to find package #11851

Closed
fowl2 opened this issue Jun 2, 2022 · 6 comments
Labels
Area:RestoreRepeatableBuild The lock file features Functionality:Restore Resolution:ByDesign This issue appears to be ByDesign

Comments

@fowl2
Copy link

fowl2 commented Jun 2, 2022

NuGet Product Used

MSBuild.exe, NuGet.exe

Product Version

NuGet 6.2

Worked before?

NuGet 6.1

Impact

It's more difficult to complete my work

Repro Steps & Context

Consider this csproj:

<Project Sdk="Microsoft.NET.Sdk">
	<PropertyGroup>
		<TargetFramework>net6.0</TargetFramework>
		<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
	</PropertyGroup>
	<ItemGroup>
		<PackageReference Include="Microsoft.CrmSdk.Data" Version="9.0.2.33" />
	</ItemGroup>
</Project>
  1. Restore project with NuGet 6.1 nuget.exe restore repro.csproj. The lock file is:
{
  "version": 1,
  "dependencies": {
    "net6.0": {
      "Microsoft.CrmSdk.Data": {
        "type": "Direct",
        "requested": "[9.0.2.33, )",
        "resolved": "9.0.2.33",
        "contentHash": "gREfQl0/mh22+eV9h8PhCnAwNY5SJswLnUPxvxJwF6L2mhj5pMFMUSvlVke3Gpk94XCrBEyIgHJzFKDiMtA1aw=="
      }
    }
  }
}
  1. Delete the obj\ directory. Restore project with NuGet 6.2. Receive error:

NU1101: Unable to find package Microsoft.CrmSdk.CoreAssemblies. No packages exist with this id in source(s): Microsoft Visual Studio Offline Packages, nuget.org

Workaround - delete the lock file. The new lock file is:

{
  "version": 1,
  "dependencies": {
    "net6.0": {
      "Microsoft.CrmSdk.Data": {
        "type": "Direct",
        "requested": "[9.0.2.33, )",
        "resolved": "9.0.2.33",
        "contentHash": "gREfQl0/mh22+eV9h8PhCnAwNY5SJswLnUPxvxJwF6L2mhj5pMFMUSvlVke3Gpk94XCrBEyIgHJzFKDiMtA1aw==",
        "dependencies": {
          "Microsoft.CrmSdk.CoreAssemblies": "9.0.2"
        }
      },
      "Microsoft.CrmSdk.CoreAssemblies": {
        "type": "Transitive",
        "resolved": "9.0.2.1",
        "contentHash": "68WUDm0RFg9RjrkxU8cTqc+bRsKa55YkG2SM81rNVMFUtNL56FlGW5gifoaABbR7KU15+myXTA/a+Vqbqc6vQQ=="
      }
    }
  }
}

Note the additional dependency on Microsoft.CrmSdk.CoreAssemblies.

The lock file generated by 6.2 is compatible with 6.1.

Verbose Logs

C:\Users\user\Downloads\test3>..\nuget-6.2.exe restore repro.csproj
MSBuild auto-detection: using msbuild version '17.2.1.25201' from 'C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\bin'.
Restoring packages for C:\Users\user\Downloads\test3\repro.csproj...
NU1101: Unable to find package Microsoft.CrmSdk.CoreAssemblies. No packages exist with this id in source(s): Microsoft Visual Studio Offline Packages, nuget.org
WARNING: NU1701: Package 'Microsoft.CrmSdk.Data 9.0.2.33' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8' instead of the project target framework 'net6.0'. This package may not be fully compatible with your project.
Generating MSBuild file C:\Users\user\Downloads\test3\obj\repro.csproj.nuget.g.props.
Generating MSBuild file C:\Users\user\Downloads\test3\obj\repro.csproj.nuget.g.targets.
Writing assets file to disk. Path: C:\Users\user\Downloads\test3\obj\project.assets.json
Failed to restore C:\Users\user\Downloads\test3\repro.csproj (in 583 ms).

Errors in C:\Users\user\Downloads\test3\repro.csproj
    NU1101: Unable to find package Microsoft.CrmSdk.CoreAssemblies. No packages exist with this id in source(s): Microsoft Visual Studio Offline Packages, nuget.org

NuGet Config files used:
    C:\Users\user\AppData\Roaming\NuGet\NuGet.Config
    C:\Program Files (x86)\NuGet\Config\Microsoft.VisualStudio.Offline.config

Feeds used:
    C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\
    https://api.nuget.org/v3/index.json


C:\Users\user\AppData\Roaming\NuGet\NuGet.Config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
  </packageSources>
</configuration>

C:\Program Files (x86)\NuGet\Config\Microsoft.VisualStudio.Offline.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <add key="Microsoft Visual Studio Offline Packages" value="C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\"/>
  </packageSources>
</configuration>
@fowl2
Copy link
Author

fowl2 commented Jun 2, 2022

The error message is a little different in build pipeline:

NU1102: Unable to find package Microsoft.CrmSdk.CoreAssemblies with version (>= 9.0.2)
  - Found 55 version(s) in NuGetOrg [ Nearest version: 9.0.2.1 ])
Full log (from a slightly more complicated sln/project):
2022-06-02T08:31:08.4583905Z ##[section]Starting: NuGetCommand
2022-06-02T08:31:08.4844196Z ==============================================================================
2022-06-02T08:31:08.4844545Z Task         : NuGet
2022-06-02T08:31:08.4845183Z Description  : Restore, pack, or push NuGet packages, or run a NuGet command. Supports NuGet.org and authenticated feeds like Azure Artifacts and MyGet. Uses NuGet.exe and works with .NET Framework apps. For .NET Core and .NET Standard apps, use the .NET Core task.
2022-06-02T08:31:08.4845845Z Version      : 2.202.0
2022-06-02T08:31:08.4846067Z Author       : Microsoft Corporation
2022-06-02T08:31:08.4846397Z Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/package/nuget
2022-06-02T08:31:08.4852840Z ==============================================================================
2022-06-02T08:31:09.6970479Z [command]"C:/Program Files/Microsoft Visual Studio/2022/Enterprise/MSBuild/Current/Bin/msbuild.exe" /version /nologo
2022-06-02T08:31:10.0210374Z SYSTEMVSSCONNECTION exists true
2022-06-02T08:31:10.1538534Z SYSTEMVSSCONNECTION exists true
2022-06-02T08:31:10.4554679Z [command]C:\Windows\system32\chcp.com 65001
2022-06-02T08:31:10.4709102Z Active code page: 65001
2022-06-02T08:31:10.5921400Z Detected NuGet version 6.2.0.146 / 6.2.0+b8a61266d9a6780cb7eb9c1942695cf813fdef0a.b8a61266d9a6780cb7eb9c1942695cf813fdef0a
2022-06-02T08:31:10.5976310Z SYSTEMVSSCONNECTION exists true
2022-06-02T08:31:10.6057811Z [command]C:\hostedtoolcache\windows\NuGet\6.2.0\x64\nuget.exe sources Add -NonInteractive -Name NuGetOrg -Source https://api.nuget.org/v3/index.json -ConfigFile D:\a\1\Nuget\tempNuGet_7765.config
2022-06-02T08:31:13.6772516Z Package source with Name: NuGetOrg added successfully.
2022-06-02T08:31:13.6899287Z [command]C:\hostedtoolcache\windows\NuGet\6.2.0\x64\nuget.exe restore D:\a\1\s\src\IBCMPlugin\IBCMPlugin.sln -Verbosity Quiet -NonInteractive -ConfigFile D:\a\1\Nuget\tempNuGet_7765.config
2022-06-02T08:32:47.2898909Z NU1102: Unable to find package Microsoft.CrmSdk.CoreAssemblies with version (>= 9.0.2)
2022-06-02T08:32:47.2900803Z   - Found 55 version(s) in NuGetOrg [ Nearest version: 9.0.2.1 ]
2022-06-02T08:32:47.2903404Z WARNING: NU1701: Package 'Microsoft.CrmSdk.Data 9.0.2.33' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8' instead of the project target framework 'net6.0'. This package may not be fully compatible with your project.
2022-06-02T08:32:47.2906733Z WARNING: NU1701: Package 'Microsoft.CrmSdk.Data 9.0.2.33' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8' instead of the project target framework 'net6.0'. This package may not be fully compatible with your project.
2022-06-02T08:32:47.2909005Z WARNING: NU1603: Microsoft.CrmSdk.Data 9.0.2.33 depends on Microsoft.CrmSdk.CoreAssemblies (>= 9.0.2) but Microsoft.CrmSdk.CoreAssemblies 9.0.2 was not found. An approximate best match of Microsoft.CrmSdk.CoreAssemblies 9.0.2.1 was resolved.
2022-06-02T08:32:47.2911350Z WARNING: NU1701: Package 'Microsoft.CrmSdk.CoreAssemblies 9.0.2.1' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8' instead of the project target framework 'net6.0'. This package may not be fully compatible with your project.
2022-06-02T08:32:47.2914561Z WARNING: NU1701: Package 'Microsoft.CrmSdk.Data 9.0.2.33' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8' instead of the project target framework 'net6.0'. This package may not be fully compatible with your project.
2022-06-02T08:32:47.2915905Z NU1102: Unable to find package Microsoft.CrmSdk.CoreAssemblies with version (>= 9.0.2)
2022-06-02T08:32:47.2920283Z   - Found 55 version(s) in NuGetOrg [ Nearest version: 9.0.2.1 ]
2022-06-02T08:32:47.2923004Z Errors in D:\a\1\s\src\DataProvider\DataProviderPlugin\DataProviderPlugin.csproj
2022-06-02T08:32:47.2923961Z     NU1102: Unable to find package Microsoft.CrmSdk.CoreAssemblies with version (>= 9.0.2)
2022-06-02T08:32:47.2924681Z       - Found 55 version(s) in NuGetOrg [ Nearest version: 9.0.2.1 ]
2022-06-02T08:32:47.2925148Z Errors in D:\a\1\s\src\IBCMPlugin\IBCM.Functions\IBCM.Functions.csproj
2022-06-02T08:32:47.2925682Z     NU1102: Unable to find package Microsoft.CrmSdk.CoreAssemblies with version (>= 9.0.2)
2022-06-02T08:32:47.2926497Z       - Found 55 version(s) in NuGetOrg [ Nearest version: 9.0.2.1 ]
2022-06-02T08:32:47.3570559Z ##[error]The nuget command failed with exit code(1) and error(NU1102: Unable to find package Microsoft.CrmSdk.CoreAssemblies with version (>= 9.0.2)
  - Found 55 version(s) in NuGetOrg [ Nearest version: 9.0.2.1 ]
NU1102: Unable to find package Microsoft.CrmSdk.CoreAssemblies with version (>= 9.0.2)
  - Found 55 version(s) in NuGetOrg [ Nearest version: 9.0.2.1 ]
Errors in D:\a\1\s\src\DataProvider\DataProviderPlugin\DataProviderPlugin.csproj
    NU1102: Unable to find package Microsoft.CrmSdk.CoreAssemblies with version (>= 9.0.2)
      - Found 55 version(s) in NuGetOrg [ Nearest version: 9.0.2.1 ]
Errors in D:\a\1\s\src\IBCMPlugin\IBCM.Functions\IBCM.Functions.csproj
    NU1102: Unable to find package Microsoft.CrmSdk.CoreAssemblies with version (>= 9.0.2)
      - Found 55 version(s) in NuGetOrg [ Nearest version: 9.0.2.1 ])
2022-06-02T08:32:47.3586968Z ##[error]Packages failed to restore
2022-06-02T08:32:47.3600275Z ##[section]Finishing: NuGetCommand

@jeffkl
Copy link
Contributor

jeffkl commented Jun 3, 2022

Thank you for filing this issue. I can confirm that the restore fails and does not regenerate the lock file. I've added this bug to our backlog to be investigated.

@jeffkl jeffkl added Resolution:ByDesign This issue appears to be ByDesign and removed Type:Bug labels Jun 3, 2022
@jeffkl
Copy link
Contributor

jeffkl commented Jun 3, 2022

We've determined this is by design due to a bug fix #5957. Multiple people have reported issues which we're tracking here: #11564

The problem is that your project targets net6.0 while the package you're referencing only supports net462 When NuGet restores, it knows that net462 is compatible with net6.0 so it restores the package anyway. In previous versions of NuGet, it would not apply the same target framework fallback logic for dependencies so Microsoft.CrmSdk.Data but Microsoft.CrmSdk.CoreAssemblies was not. In the newest version of NuGet, this bug is fixed so Microsoft.CrmSdk.CoreAssemblies is now being restored when it wasn't before. I guess you aren't using any assets from Microsoft.CrmSdk.CoreAssemblies so you never noticed it wasn't in the restore graph.

The workaround for this is to add -ForceEvaluate to the command-line to regenerate the lock file once or delete the lock file and regenerate it.

D:\repros\lockfile-transitive>rd /s /q obj & C:\Users\jeffkl\Downloads\nuget6.2.exe restore Test.csproj -ForceEvaluate
MSBuild auto-detection: using msbuild version '17.2.1.25201' from 'C:\Program Files\Visual Studio 2022\MSBuild\Current\Bin\amd64'.
Restoring packages for D:\repros\lockfile-transitive\Test.csproj...
  GET https://api.nuget.org/v3-flatcontainer/microsoft.crmsdk.coreassemblies/index.json
  OK https://api.nuget.org/v3-flatcontainer/microsoft.crmsdk.coreassemblies/index.json 223ms
WARNING: NU1701: Package 'Microsoft.CrmSdk.CoreAssemblies 9.0.2.1' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8' instead of the project target framework 'net6.0'. This package may not be fully compatible with your project.
WARNING: NU1701: Package 'Microsoft.CrmSdk.Data 9.0.2.33' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8' instead of the project target framework 'net6.0'. This package may not be fully compatible with your project.
Generating MSBuild file D:\repros\lockfile-transitive\obj\Test.csproj.nuget.g.props.
Generating MSBuild file D:\repros\lockfile-transitive\obj\Test.csproj.nuget.g.targets.
Writing assets file to disk. Path: D:\repros\lockfile-transitive\obj\project.assets.json
Writing packages lock file at disk. Path: D:\repros\lockfile-transitive\packages.lock.json
Restored D:\repros\lockfile-transitive\Test.csproj (in 1.59 sec).

NuGet Config files used:
    C:\Users\jeffkl\AppData\Roaming\NuGet\NuGet.Config
    C:\Program Files (x86)\NuGet\Config\Microsoft.VisualStudio.Offline.config

Feeds used:
    C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\
    https://api.nuget.org/v3/index.json

D:\repros\lockfile-transitive>type packages.lock.json
{
  "version": 1,
  "dependencies": {
    "net6.0": {
      "Microsoft.CrmSdk.Data": {
        "type": "Direct",
        "requested": "[9.0.2.33, )",
        "resolved": "9.0.2.33",
        "contentHash": "gREfQl0/mh22+eV9h8PhCnAwNY5SJswLnUPxvxJwF6L2mhj5pMFMUSvlVke3Gpk94XCrBEyIgHJzFKDiMtA1aw==",
        "dependencies": {
          "Microsoft.CrmSdk.CoreAssemblies": "9.0.2"
        }
      },
      "Microsoft.CrmSdk.CoreAssemblies": {
        "type": "Transitive",
        "resolved": "9.0.2.1",
        "contentHash": "68WUDm0RFg9RjrkxU8cTqc+bRsKa55YkG2SM81rNVMFUtNL56FlGW5gifoaABbR7KU15+myXTA/a+Vqbqc6vQQ=="
      }
    }
  }
}

@fowl2
Copy link
Author

fowl2 commented Jun 4, 2022

It may be designed to encourage package authors to improve their packages, but in reality it's hurting the multitude higher number of package consumers that have no to limited influence.

Such a breaking change should have a lock file version bump/marker, at the very least.

Even if an author does fix their package, each consumer still has a broken build untill they can upgrade. Every servicing branch has to consider extra package upgrades. Additionally because this is in a minor update/not tied to a VS major release, one can't even "just" recommend side by side install eg. VS 2019.

Consider the number of first party packages affected and how most users won't even consider finding this issue on GitHub based on the error messages, and there's nothing obviously related in the release notes/known issues.

If the package authoring problem is so serious, perhaps start with warnings and errors at packaging time (not consumption), and maybe follow up with warnings on package pages or even direct outreach.

@fowl2
Copy link
Author

fowl2 commented Jun 4, 2022

Note that I'm all for the problems being detected at build rather than runtime. Staticly analyse all the things! (but not crying wolf :)

@nkolev92
Copy link
Member

nkolev92 commented Jun 7, 2022

Hey @fowl2,

In this case, the package is authored correctly, but a bug caused a bad resolution.

Please follow #11564, where we will consider adding a switch to revert to the old behavior.

Please note that the recommendation is that you migrate to the new tooling as the new behavior is the correct one.

@nkolev92 nkolev92 closed this as completed Jun 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area:RestoreRepeatableBuild The lock file features Functionality:Restore Resolution:ByDesign This issue appears to be ByDesign
Projects
None yet
Development

No branches or pull requests

3 participants