豆豆友情提示:这是一个非官方 GitHub 代理镜像,主要用于网络测试或访问加速。请勿在此进行登录、注册或处理任何敏感信息。进行这些操作请务必访问官方网站 github.com。 Raw 内容也通过此代理提供。
Skip to content

Locked mode not working as hash is calculated incorrectly for previously cached packages #7682

@alefranz

Description

@alefranz

Details about Problem

I've been struggling with the new "locked mode" of dotnet restore since release and I've finally been able to create repro steps.

The problems seems related to using different version of the .NET Core SDK on the same machine, in particular versions before the locked mode introduction alongside the new ones.
As the NuGet Package Cache is shared between all versions, if the package as been cached by an old version of dotnet.exe/nuget, it looks like the new .nupkg.metadata get created with an incorrect signature.

Example:
Newtonsoft.Json 12.0.1 has signature:

{
  "version": 1,
  "contentHash": "jmVyoEyk0In8r+AObYQyFKVFm7uSRzE0XSHSbEtBJcZDMV6DqJoyB4FLcHwprPVhAh826so0db3DIKXVnpGoPA=="
}

however if it was already in the Nuget Package Cache, when using the new dotnet.exe/nuget it get this signature

{
  "version": 1,
  "contentHash": "pBR3wCgYWZGiaZDYP+HHYnalVnPJlpP1q55qvVb+adrDHmFMDc1NAKio61xTwftK3Pw5h7TZJPJEEVMd6ty8rg=="
}

which obviously cause the locked mode feature to fail.

This behaviour seems consistent in different Windows versions and machines.
Not tested on Linux/MaxOs.

I believe it is a common scenario to use different versions of the SDK on a dev machine as well on a build agent (not everyone use disposable docker agents yet) e.g. via global.json in different projects

Happy to help investigate more but I will need someone to point me in the right direction.

Thank you

Product Versions

NuGet product used: dotnet.exe

Version pre locked mode used:
❯ dotnet --version
2.1.403
❯ dotnet nuget --version
NuGet Command Line
4.8.1.0

Version with locked mode used:
❯ dotnet --version
2.2.102
❯ dotnet nuget --version
NuGet Command Line
4.9.2.0

OS version: Win10 17763

Worked before? No

Detailed repro steps so we can see the same problem

  1. git clone https://github.com/alefranz/DotnetRestoreLockedMode
  2. Delete package from Nuget package cache in %userprofile%.nuget\packages\newtonsoft.json\12.0.1
  3. cd DotnetRestoreLockedMode\NetSdk22
  4. dotnet restore --force --force-evaluate
  5. dotnet restore --force --locked-mode pass!
  6. Delete package from Nuget package cache in %userprofile%.nuget\packages\newtonsoft.json\12.0.1
  7. cd ..\NetSdk21
  8. dotnet restore --force
  9. cd ..\NetSdk22
  10. dotnet restore --force --locked-mode fail! :(

Sample Project

https://github.com/alefranz/DotnetRestoreLockedMode

Note the global.json is at the project level for simplicity, but it doesn't make any difference having different solutions.

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions