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

dotnet build fails with error NU1008 when directory tree contains multiple Directory.Packages.props files. #40445

Open
voroninp opened this issue Apr 25, 2024 · 8 comments
Assignees
Milestone

Comments

@voroninp
Copy link

voroninp commented Apr 25, 2024

Describe the bug

I have a repository with multiple Directory.Packages.props files. I want to exclude some projects (tools directory) from central package management.
I can build solution in VS Version 17.9.6 (fails with Version 17.10.0 Preview 5.0) without issues, but dotnet build command fails with this error:

error NU1008: Projec
ts that use central package version management should not define the version on the PackageReference items but on the P
ackageVersion items: coverlet.collector;Microsoft.NET.Test.Sdk;xunit;xunit.runner.visualstudio.

It looks like the closest Directory.Packages.props file is ignored.

To Reproduce

Here is the solution to reproduce the issue (sln file is in Json.TestLogger directory):
CliBug.zip

Further technical details

  • Include the output of dotnet --info
.NET SDK:
 Version:           8.0.300-preview.24203.14
 Commit:            b7e38f457d
 Workload version:  8.0.300-manifests.1f2e3bea
 MSBuild version:   17.10.0+4f6b1bb28

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.22631
 OS Platform: Windows
 RID:         win-x64
 Base Path:   C:\Program Files\dotnet\sdk\8.0.300-preview.24203.14\

.NET workloads installed:
 [android]
   Installation Source: SDK 8.0.300-preview.24203, VS 17.10.34818.151, VS 17.9.34728.123
   Manifest Version:    34.0.95/8.0.100
   Manifest Path:       C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.sdk.android\34.0.95\WorkloadManifest.json
   Install Type:        FileBased

 [ios]
   Installation Source: SDK 8.0.300-preview.24203, VS 17.10.34818.151, VS 17.9.34728.123
   Manifest Version:    17.2.8053/8.0.100
   Manifest Path:       C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.sdk.ios\17.2.8053\WorkloadManifest.json
   Install Type:        FileBased

 [maccatalyst]
   Installation Source: SDK 8.0.300-preview.24203, VS 17.10.34818.151, VS 17.9.34728.123
   Manifest Version:    17.2.8053/8.0.100
   Manifest Path:       C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.sdk.maccatalyst\17.2.8053\WorkloadManifest.json
   Install Type:        FileBased

 [maui-windows]
   Installation Source: SDK 8.0.300-preview.24203, VS 17.10.34818.151, VS 17.9.34728.123
   Manifest Version:    8.0.7/8.0.100
   Manifest Path:       C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.sdk.maui\8.0.7\WorkloadManifest.json
   Install Type:        FileBased

 [wasm-tools]
   Installation Source: SDK 8.0.300-preview.24203, VS 17.10.34818.151, VS 17.9.34728.123
   Manifest Version:    8.0.4/8.0.100
   Manifest Path:       C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.workload.mono.toolchain.current\8.0.4\WorkloadManifest.json
   Install Type:        FileBased


Host:
  Version:      8.0.4
  Architecture: x64
  Commit:       2d7eea2529

.NET SDKs installed:
  7.0.408 [C:\Program Files\dotnet\sdk]
  8.0.204 [C:\Program Files\dotnet\sdk]
  8.0.300-preview.24203.14 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.All 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.27 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.29 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 7.0.16 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 7.0.18 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 8.0.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 8.0.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.27 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.29 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 7.0.16 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 7.0.18 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 8.0.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 8.0.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 6.0.27 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 6.0.29 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 7.0.16 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 7.0.18 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 8.0.2 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 8.0.4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found:
  x86   [C:\Program Files (x86)\dotnet]
    registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

Environment variables:
  Not set

global.json file:
  Not found

Learn more:
  https://aka.ms/dotnet/info

Download .NET:
  https://aka.ms/dotnet/download

I've put global.json in root folder and it fixed the cli, but VS Version 17.10.0 Preview 5.0 still does not build.

{
  "sdk": {
    "version": "8.0.204"
  }
}
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Workloads untriaged Request triage from a team member labels Apr 25, 2024
@voroninp voroninp changed the title [8.0.300-preview.24203.14] dotnet build fails with error NU1008 when directory tree contains multiple Directory.Packages.props files. dotnet build fails with error NU1008 when directory tree contains multiple Directory.Packages.props files. Apr 25, 2024
@marcpopMSFT marcpopMSFT self-assigned this Apr 26, 2024
@marcpopMSFT
Copy link
Member

Without a global.json, build in VS works but dotnet build fails but if you pin to the 8.0.204 SDK, the VS build fails but the dotnet build succeeds? What folder are you running dotnet build in? In VS, what project/solution are you opening?

The logic for how to load the directory.build.props file comes from the common props in msbuild. CC @dotnet/kitten to comment on the best way to get the experience you want.

@marcpopMSFT marcpopMSFT added Area-NetSDK and removed untriaged Request triage from a team member Area-Workloads labels Apr 26, 2024
@marcpopMSFT marcpopMSFT added this to the Discussion milestone Apr 26, 2024
@voroninp
Copy link
Author

In preview VS it fails always.
In stable version VS it works irrespective of global.json

dotnet build fails without global.json, but succeeds when pinned to 8.0.204

@rainersigwald
Copy link
Member

This is a behavior change caused by NuGet/NuGet.Client#5572.

@JonDouglas called it out as a breaking change in NuGet/Home#11834 but I'm not sure that's documented as such yet. @jeffkl fyi.

@voroninp
Copy link
Author

@rainersigwald , how do I disable it for the subtree then (tools solution)?

Directory.Build.props
Directory.Package.props
src
tools
     | 
     - Directory.Build.props
     - tools.sln

@rainersigwald
Copy link
Member

Explicitly set

<PropertyGroup>
  <ManagePackageVersionsCentrally>false</ManagePackageVersionsCentrally>
</PropertyGroup>

in the nested Directory.Packages.props.

@voroninp
Copy link
Author

Ah, so I need to create it as well. Ok, thanks.

@omer-za
Copy link

omer-za commented May 15, 2024

Is there a way to keep it default as false?
I have a generated project using openapi generator that doesn't set it to false and every time I generate files I need to modify manually all csproj files :(

omer-za added a commit to omer-za/openapi-generator that referenced this issue May 20, 2024
wing328 pushed a commit to OpenAPITools/openapi-generator that referenced this issue May 23, 2024
@amis92
Copy link

amis92 commented May 23, 2024

I've created empty Directory.Packages.props to disable CPM at some level.

  • Why was this introduced so late, if the issue was from 2022? CPVM was stabilized with 8.0.100 as LTS. Two bands later, breaking change.
  • Why breaking changes within SDK feature bands?
  • Why is this not documented?

image

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

5 participants