question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`dotnet restore` doesn't restore dependencies included in a `.props` file from a referenced package

See original GitHub issue

Describe the bug

dotnet restore doesn’t restore dependencies included in a .props file from a referenced package’s build folder. The expected obj/*.nuget.g.props is generated when the project is loaded in Visual Studio, but it is promptly overwritten when running either dotnet restore or dotnet build.

To Reproduce

Build the attached reproduction solution, ConsumingPackage/ConsumingPackage.sln, in Visual Studio and take a look at the obj/ConsumingPackage.csproj.nuget.g.props file. Then, run dotnet build on the same solution to see the build fail and modify the aforementioned .props file to exclude the referenced package, JetBrains.Annotations.

NuGetPropsBug.zip

Exceptions

NuGetPropsBug\ConsumingPackage\Class1.cs(5,6): error CS0246: The type or namespace name 'PublicAPIAttribute' could not be found (are you missing a using directive or an assembly reference?)

Further technical details

.NET SDK (reflecting any global.json):
 Version:   6.0.400
 Commit:    7771abd614

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.22000
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\6.0.400\

global.json file:
  Not found

Host:
  Version:      6.0.8
  Architecture: x64
  Commit:       55fb7ef977

.NET SDKs installed:
  3.1.422 [C:\Program Files\dotnet\sdk]
  6.0.202 [C:\Program Files\dotnet\sdk]
  6.0.203 [C:\Program Files\dotnet\sdk]
  6.0.303 [C:\Program Files\dotnet\sdk]
  6.0.400 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 3.1.28 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 3.1.24 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.28 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.1.24 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 3.1.28 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 6.0.3 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 6.0.4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 6.0.5 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 6.0.8 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Visual Studio 17.3.1

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
gtbuchanancommented, Aug 24, 2022

@baronfel I appreciate you taking a look at this. It’s essentially a meta package. We have many repositories that share a common configuration and I was trying to have a single package that intelligently references necessary analyzers and common packages based on convention (e.g. the assembly does/doesn’t end with .Test, has certain MSBuild properties, uses certain target frameworks). I should be able to move most of the references directly into the project as you suggested and use multi-targeting. Doesn’t sound like the conditional logic based on assembly naming or MSBuild properties will work, though.

@nkolev92 Thank you for the reference! I can’t believe I didn’t come across that page in my research…

1reaction
nkolev92commented, Aug 23, 2022

That is correct, PackageReference (and in general NuGet restore affecting props/items) are not supported in the props/targets of packages.

https://docs.microsoft.com/en-us/nuget/concepts/msbuild-props-and-targets#guidance-for-the-content-of-msbuild-props-and-targets

Read more comments on GitHub >

github_iconTop Results From Across the Web

PackageReference defined in .props file not appearing in ...
I have a tools.props file which contains some PackageReference's. When I import the file into a .csproj either via or via a NuGet...
Read more >
dotnet restore command - .NET CLI
Learn how to restore dependencies and project-specific tools with the dotnet restore command.
Read more >
PackageReference in project files - NuGet
In this article ... Package references, using <PackageReference> MSBuild items, specify NuGet package dependencies directly within project files, ...
Read more >
dotnet restore keeps using local project instead of nuget ...
In it, I used a Nuget package, but after finding a bug in the package, I checked out its source code and included...
Read more >
Paket and the .NET SDK / .NET Core CLI tools (dotnet CLI ...
Create a paket.dependencies file in your project's root and specify all your ... After paket.references files files have been created, run dotnet restore...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found