Net5 wildcard package reference causes "NU1004: The packages lock file is inconsistent" error in in locked mode

259 Views Asked by At

I have created 2 projects in aspnet: 1 web project and one class library that references the first one:

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

    <PropertyGroup>
        <TargetFramework>net5.0</TargetFramework>
        <RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
    </PropertyGroup>

    <ItemGroup>
        <PackageReference Include="Dapper" Version="2.*" />
    </ItemGroup>

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

    <PropertyGroup>
        <TargetFramework>net5.0</TargetFramework>
        <RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
    </PropertyGroup>
    

    <ItemGroup>
      <ProjectReference Include="..\WebApplication\WebApplication.csproj" />
    </ItemGroup>

</Project>

It is as simple as it gets, just vanilla new projects. Now if I run

dotnet restore --force-evaluate
dotnet restore --locked-mode

I get this error (after second command):

C:\Source\Test\WebApplication1\ClassLibrary1\ClassLibrary1.csproj : error NU1004: The project references webapplication whose dependencies has changed.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. [C:\Source\Test\WebAppl ication1\WebApplication1.sln]

If the reference is not wildcard, it works properly. I don't quite understand why this error happens and if I am doing something wrong. From the looks of it I'd say this is a bug.

0

There are 0 best solutions below