Using central package management causes build breaking NU1009 with MAUI projects
See original GitHub issueDescription
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
- Clone the attached reproduction project repository
- 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:
- Created 8 months ago
- Reactions:8
- Comments:41 (16 by maintainers)
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.
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 yourDirectory.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:The
$(UseMaui)' != 'true'
condition here disables the<PackageVersion />
item for Maui projects and fixes the NU1009 error.