NuGet / Home

Repo for NuGet Client issues
Other
1.49k stars 250 forks source link

VS restore won't respect project prefix in the lock file #13663

Open martinrrm opened 1 month ago

martinrrm commented 1 month ago

Internal ticket: https://devdiv.visualstudio.com/DevDiv/_workitems/edit/2172224

This is a weird bug, when you are using lock files and have a ProjectA referencing ProjectB and add a prefix in the Directory.Build.props with a PackageReference to Nugetizer, the lock file is going to produce different outputs depending on where restore was made.

VS will output something like this:

{
  "version": 1,
  "dependencies": {
    "net8.0": {
      "referencedproject": {
        "type": "Project"
      }
    }
  }
}

While doing a dotnet restore it will result in:

{
  "version": 1,
  "dependencies": {
    "net8.0": {
      "A.Prefix.ReferencedProject": {
        "type": "Project"
      }
    }
  }
}

Example Directory.Build.props:

<Project>
  <PropertyGroup>
    <LangVersion>latest</LangVersion>
    <RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>

    <AssemblyPreffix Condition="$(AssemblyPreffix) == ''">A.Prefix</AssemblyPreffix>
    <AssemblyName Condition="$(AssemblyName) == ''">$(MSBuildProjectName)</AssemblyName>
    <AssemblyName Condition="!$(AssemblyName.StartsWith(AssemblyPreffix))">$(AssemblyPreffix).$(AssemblyName)</AssemblyName>
  </PropertyGroup>

  <ItemGroup Condition="!$(MSBuildProjectName.Contains('ReferencedProject'))">
    <ProjectReference Include="..\ReferencedProject\ReferencedProject.csproj" />
  </ItemGroup>
</Project>

Example ReferencedProject.csproj:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="NuGetizer" Version="*">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
  </ItemGroup>
</Project>
dotnet-policy-service[bot] commented 1 month ago

@martinrrm Issue is missing Type label, remember to add a Type label

nkolev92 commented 3 weeks ago

Assigning to hotseat for investigation

jebriede commented 2 weeks ago

Team Triage: Assigning to current hotseat for investigation

kartheekp-ms commented 6 days ago

I am able to reproduce this issue in VS 2022 versions 17.11.2, 17.12 public preview, and internal preview.

I noticed an odd behavior, but I haven't identified the root cause yet.

vs-restore-nugetizer

jeffkl commented 2 days ago

@voroninp I believe the repro has bad MSBuild syntax which I've fixed at https://github.com/voroninp/BadRestore/pull/1 and now the lock file is properly regenerated in VS for me.

voroninp commented 2 days ago

@jeffkl , hi, I'll be able to check in a week. Thanks.