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

Improve NU1004 when pruning is used with locked mode #14075

Open
nkolev92 opened this issue Jan 30, 2025 · 0 comments
Open

Improve NU1004 when pruning is used with locked mode #14075

nkolev92 opened this issue Jan 30, 2025 · 0 comments

Comments

@nkolev92
Copy link
Member

nkolev92 commented Jan 30, 2025

Start with

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net9.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="NuGet.Commands" Version="6.9.1" />
  </ItemGroup>

</Project>
  1. dotnet restore --use-lock-file
  2. Enable pruning by setting <RestoreEnablePackagePruning>true</RestoreEnablePackagePruning>
  3. dotnet restore --locked-mode

The missing package detection logic should be able to detect that a package was pruned, or at the minimum report that pruning has been enable and provide remediation.

Currently for a failure you can get something like:

error NU1004: The package reference NuGet.Commands version has changed from [6.9.1, ) to [6.8.1, ).The packages lock file is inconsistent with the project dependencies so restore can't be run in locked mode. Disable the RestoreLockedMode MSBuild property or pass an explicit --force-evaluate option to run restore to update the lock file.

We should be able to do something along the lines of

error NU1004: A new package reference was found System.Formats.Asn1 for the project target framework. This is due to package pruning being enabled .The packages lock file is inconsistent with the project dependencies so restore can't be run in locked mode. Disable the RestoreLockedMode MSBuild property or pass an explicit --force-evaluate option to run restore to update the lock file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant