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.

Using central package management causes build breaking NU1009 with MAUI projects

See original GitHub issue

Description

Building a MAUI project using central package management does not seem possible because of the NU1009 error. It reads as a warning, but is in fact a build breaking error.

I attached a minimal reproduction containing a MAUI project and a library that this project depends on, which itself requires the ILogger abstraction from Microsoft.Extensions.Logging.Abstractions,. If you build it as is, the build fails with:

error NU1009: The packages Microsoft.Extensions.Logging.Abstractions;Microsoft.Extensions.Logging.Abstractions;Microsoft.Extensions.Logging.Abstractions;Microsoft.Extensions.Logging.Abstractions 
 are implicitly referenced. You do not typically need to reference them from your project or in your central package versions management file. For more information, see https://aka.ms/sdkimplicitrefs

If you fix this error by removing the reference to Microsoft.Extensions.Logging.Abstractions (what the error suggests you do), the build fails with a collection of errors, due to the fact that the ILogger interface is cannot be found anymore in the library which the MAUI project depends on.

I also tried using https://learn.microsoft.com/en-gb/dotnet/core/project-sdk/msbuild-props#disableimplicitframeworkreferences, but it seems it is ignored altogether and has no effect.

Moreover, it doesn’t seem to happen with other project types such as web API or console app.

Steps to Reproduce

  1. Clone the attached reproduction project repository
  2. Run dotnet build at the root of the cloned repo

Link to public reproduction project repository

https://github.com/hypdeb/repros

Version with bug

7.0 (current)

Last version that worked well

Unknown/Other

Affected platforms

Windows

Affected platform versions

This is a build failure

Did you find any workaround?

No response

Relevant log output

No response

Issue Analytics

  • State:open
  • Created 8 months ago
  • Reactions:8
  • Comments:41 (16 by maintainers)

github_iconTop GitHub Comments

3reactions
mattleibowcommented, Aug 18, 2023

I think that may be a good idea tbh… I see the Microsoft.Extensions packages have more than one tfm… I am thinking essentials and graphics could fall into this category. The main maui framework is tfm specific, but the extras are extensions… Let me do a PR and see what shakes out. Probably can do the same for resizetizer as well…

Thanks for this idea that I totally should have considered since I did nuget analysis when we transitioned.

2reactions
jeffklcommented, Jan 30, 2023

The Maui SDK injects package references for you implicitly: https://github.com/dotnet/maui/blob/main/src/Workload/Microsoft.Maui.Sdk/Sdk/BundledVersions.in.targets#L70

When you manage your package versions centrally, NuGet does not want you to define versions for implicitly defined package references since an SDK is trying to manage it for you.

In order to have a <PackageVersion /> in your Directory.Packages.props for a package but not get this error, you’ll need to condition it so that when building a Maui project it is not defined:

<Project>
  <PropertyGroup>
    <ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
  </PropertyGroup>
  <ItemGroup>
    <PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" Condition="'$(UseMaui)' != 'true'" />
  </ItemGroup>
</Project>

The $(UseMaui)' != 'true' condition here disables the <PackageVersion /> item for Maui projects and fixes the NU1009 error.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using central package management causes build breaking ...
Using central package management causes build breaking NU1009 with MAUI projects · Summary · Jobs. Rebase · Run details. Usage · Workflow file....
Read more >
MAUI solution with apps and DLLs fails to generate ...
Hello! When I package the DLL in addition to the application in the MAUI solution, it fails with the following error.
Read more >
Central Package Management
Manage your dependencies in a central location and how you can get started with central package management.
Read more >
Nuget package downgrade on .NET 6 Docker build using ...
NET 6 image, it downgrades several of my packages to an old incompatible version. I'm using Central Package Management. Here's the dockerfile - ......
Read more >
NuGet package: Simple Rating Control for .NET MAUI
I've already published a post showing how to create a simple rating control which can be used in .NET MAUI using an icon...
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