Skip to content

[msbuild] fix NuGet Central Package Management (CPM) - #17235

Merged
rmarinho merged 1 commit into
dotnet:mainfrom
jonathanpeppers:NuGetCentralPackageManagement
Sep 7, 2023
Merged

rmarinho merged 1 commit into
dotnet:mainfrom
jonathanpeppers:NuGetCentralPackageManagement

Conversation

@jonathanpeppers

@jonathanpeppers jonathanpeppers commented Sep 6, 2023 •

Copy link
Copy Markdown
Member

Context: https://learn.microsoft.com/nuget/consume-packages/Central-Package-Management
Fixes #12953

@mattleibow has already made a few changes to improve this scenario, by introducing $(DisableMauiImplicitPackageReferences).

I think the main thing missing is to change default values when $(ManagePackageVersionsCentrally) is true. This setting, that enables CPM, should automatically turn off all implicit @(PackageReference).

I renamed $(EnableMauiImplicitPackageReferences) to $(DisableMauiImplicitPackageReferences) to better align with the changes we made in MAUI in .NET 7 for a future servicing release:

#17046

I tested these changes in a sample application here:

jdebache/repros@master...jonathanpeppers:MauiNuGetCPMRepro:peppers

I also updated Workload/README.md to have a section showing how to setup NuGet CPM.

Context: https://learn.microsoft.com/nuget/consume-packages/Central-Package-Management
Fixes: dotnet#12953

@mattleibow has already made a few changes to improve this scenario, by
introducing `$(DisableMauiImplicitPackageReferences)`.

I think the main thing missing is to change default values when
`$(ManagePackageVersionsCentrally)` is true. This setting, that enables
CPM, should automatically turn off all implicit `@(PackageReference)`.

I renamed `$(EnableMauiImplicitPackageReferences)` to
`$(DisableMauiImplicitPackageReferences)` to better align with the
changes we made in MAUI in .NET 7 for a future servicing release:

dotnet#17046

I tested these changes in a sample application here:

jdebache/repros@master...jonathanpeppers:MauiNuGetCPMRepro:peppers

I also updated `Workload/README.md` to have a section showing how to
setup NuGet CPM.
@jonathanpeppers
jonathanpeppers requested a review from a team as a code owner September 6, 2023 14:39
@jonathanpeppers jonathanpeppers added area-single-project Splash Screen, Multi-Targeting, MauiFont, MauiImage, MauiAsset, Resizetizer area-infrastructure CI, Maestro / Coherency, upstream dependencies/versions labels Sep 6, 2023
@samhouts samhouts added this to the .NET 8 GA milestone Sep 6, 2023
@jdebache

jdebache commented Sep 7, 2023

Copy link
Copy Markdown

I can't review, but looking at the results in the repro, it seems like it does what it's expected to, i.e. allow overriding implicit package references from MAUI when central package management is used, so, for what it's worth, LGTM :)

@rmarinho
rmarinho merged commit a1cf538 into dotnet:main Sep 7, 2023
@jonathanpeppers
jonathanpeppers deleted the NuGetCentralPackageManagement branch September 7, 2023 13:56
@LeDahu22

Copy link
Copy Markdown

@jonathanpeppers Could your write a complete documentation on how to use CPM with MAUI please ? The example you provided doesn't seem to work as provided. I bit more explanation would be welcome 😄

@MartyIX

MartyIX commented Nov 29, 2023

Copy link
Copy Markdown
Contributor

@jonathanpeppers Could your write a complete documentation on how to use CPM with MAUI please ? The example you provided doesn't seem to work as provided. I bit more explanation would be welcome 😄

What errors do yout get?

It might be easy for you to create a new MAUI project here on Github and point us there. CPM works for me so I can probably spot an issue. Then it would serve as a documentation or source for documentation efforts.

@LeDahu22

LeDahu22 commented Nov 29, 2023 •

Copy link
Copy Markdown

Hi @MartyIX

Here is my Directory.Packages.props

<Project>
  <PropertyGroup>
    <ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
  </PropertyGroup>
  <ItemGroup>
	  <PackageVersion Include="ApkNet" Version="1.0.0" />
	  <PackageVersion Include="Azure.Identity" Version="1.10.4" />
	  <PackageVersion Include="ClosedXML" Version="0.102.1" />
	  <PackageVersion Include="ColorHelper" Version="1.8.1" />
	  <PackageVersion Include="CommandLineParser" Version="2.9.1" />
	  <PackageVersion Include="Community.Archives.Apk" Version="1.2.0" />
	  <PackageVersion Include="CommunityToolkit.Maui" Version="7.0.0" />
	  <PackageVersion Include="CommunityToolkit.Maui.Core" Version="7.0.0" />
	  <PackageVersion Include="CommunityToolkit.Maui.Markup" Version="4.0.0" />
	  <PackageVersion Include="CommunityToolkit.Mvvm" Version="8.2.2" />
	  <PackageVersion Include="CsvHelper" Version="30.0.1" />
	  <PackageVersion Include="EFCore.BulkExtensions" Version="8.0.0" />
	  <PackageVersion Include="FluentMigrator" Version="3.3.2" />
	  <PackageVersion Include="FluentMigrator.Runner" Version="3.3.2" />
	  <PackageVersion Include="FluentMigrator.Runner.SQLite" Version="3.3.2" />
	  <PackageVersion Include="FluentValidation" Version="11.8.1" />
	  <PackageVersion Include="LinqKit" Version="1.2.5" />
	  <PackageVersion Include="Microsoft.CSharp" Version="4.7.0" />
	  <PackageVersion Include="Microsoft.Data.SqlClient" Version="5.1.2" />
	  <PackageVersion Include="Microsoft.Data.Sqlite.Core" Version="8.0.0" />
	  <PackageVersion Include="Microsoft.DotNet.UpgradeAssistant.Extensions.Default.Analyzers" Version="0.4.421302" />
	  <PackageVersion Include="Microsoft.EntityFrameworkCore" Version="8.0.0" />
	  <PackageVersion Include="Microsoft.EntityFrameworkCore.Abstractions" Version="8.0.0" />
	  <PackageVersion Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.0" />
	  <PackageVersion Include="Microsoft.EntityFrameworkCore.Relational" Version="8.0.0" />
	  <PackageVersion Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.0" />
	  <PackageVersion Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.0" />
	  <PackageVersion Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="8.0.0" />
	  <PackageVersion Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.0" />
	  <PackageVersion Include="Microsoft.Extensions.Configuration" Version="8.0.0" Condition="'$(UseMaui)' != 'true'" />
	  <PackageVersion Include="Microsoft.Extensions.Configuration.Abstractions" Version="8.0.0" />
	  <PackageVersion Include="Microsoft.Extensions.Configuration.FileExtensions" Version="8.0.0" />
	  <PackageVersion Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
	  <PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" Condition="'$(UseMaui)' != 'true'" />
	  <PackageVersion Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
	  <PackageVersion Include="Microsoft.Extensions.Hosting.Abstractions" Version="8.0.0" />
	  <PackageVersion Include="Microsoft.Extensions.Logging.Debug" Version="8.0.0" />
	  <PackageVersion Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="8.0.0" />
	  <PackageVersion Include="Microsoft.Maui.Core" Version="8.0.3" />
	  <PackageVersion Include="Microsoft.Maui.Controls" Version="8.0.3" />
	  <PackageVersion Include="Microsoft.Maui.Controls.Core" Version="8.0.3" />
	  <PackageVersion Include="Microsoft.Maui.Controls.Build.Tasks" Version="8.0.3" />
	  <PackageVersion Include="Microsoft.Maui.Controls.Xaml" Version="8.0.3" />
	  <PackageVersion Include="Microsoft.Maui.Essentials" Version="8.0.3" />
	  <PackageVersion Include="Microsoft.Maui.Resizetizer" Version="8.0.3" />
	  <PackageVersion Include="Microsoft.Windows.Compatibility" Version="8.0.0" />
	  <PackageVersion Include="NPOI" Version="2.6.2" />
	  <PackageVersion Include="PublicHoliday" Version="2.33.0" />
	  <PackageVersion Include="Scrutor" Version="4.2.2" />
	  <PackageVersion Include="Serilog" Version="3.1.1" />
	  <PackageVersion Include="Serilog.Formatting.Compact" Version="2.0.0" />
	  <PackageVersion Include="Serilog.Formatting.Compact.Reader" Version="3.0.0" />
	  <PackageVersion Include="Serilog.Sinks.Console" Version="4.1.0" />
	  <PackageVersion Include="Serilog.Sinks.Debug" Version="2.0.0" />
	  <PackageVersion Include="Serilog.Sinks.File" Version="5.0.0" />
	  <PackageVersion Include="Serilog.Sinks.Seq" Version="6.0.0" />
	  <PackageVersion Include="SharpZipLib" Version="1.4.2" />
	  <PackageVersion Include="System.ComponentModel.Annotations" Version="5.0.0" />
	  <PackageVersion Include="System.Configuration.ConfigurationManager" Version="8.0.0" />
	  <PackageVersion Include="System.Data.DataSetExtensions" Version="4.5.0" />
	  <PackageVersion Include="System.Drawing.Common" Version="7.0.0" />
	  <PackageVersion Include="System.IO.Ports" Version="8.0.0" />
	  <PackageVersion Include="System.Linq.Async" Version="6.0.1" />
	  <PackageVersion Include="System.Resources.ResourceManager" Version="4.3.0" />
	  <PackageVersion Include="System.Text.Json" Version="8.0.0" />
	  <PackageVersion Include="Telerik.UI.for.Maui" Version="6.5.0" />
	  <PackageVersion Include="UI.for.WinForms.AllControls.Net70" Version="2023.3.1114" />
	  <PackageVersion Include="Ude.NET" Version="1.0.0" />
	  <PackageVersion Include="UniversalTypeConverter" Version="2.6.0" />
	  <PackageVersion Include="Xamarin.AndroidX.Activity" Version="1.8.1.1" />
	  <PackageVersion Include="Xamarin.AndroidX.Activity.Ktx" Version="1.8.1.1" />
	  <PackageVersion Include="Xamarin.AndroidX.Preference" Version="1.2.1.3" />
	  <PackageVersion Include="Xamarin.Google.Android.Material" Version="1.10.0.2" />
	  <PackageVersion Include="banditoth.MAUI.DeviceId" Version="1.0.0" />
  </ItemGroup>
</Project>

Here is my MAUI .csproj file, for nuget references :

<PropertyGroup>
		<TargetFrameworks>net8.0-android</TargetFrameworks>
		<OutputType>Exe</OutputType>
		<RootNamespace>NDC.Mobile</RootNamespace>
		<UseMaui>true</UseMaui>
		<SingleProject>true</SingleProject>
		<ImplicitUsings>enable</ImplicitUsings>
		<Nullable>disable</Nullable>
		<LangVersion>Latest</LangVersion>
		<RuntimeIdentifiers>android-arm64</RuntimeIdentifiers>

		<AndroidUseLatestPlatformSdk>false</AndroidUseLatestPlatformSdk>
</PropertyGroup>

<!-- A bunch of other things -->

<ItemGroup>
	<PackageReference Include="Azure.Identity" />
	<PackageReference Include="banditoth.MAUI.DeviceId" />
	<PackageReference Include="CommunityToolkit.Maui" />
	<PackageReference Include="CommunityToolkit.Maui.Core" />
	<PackageReference Include="CommunityToolkit.Maui.Markup" />
	<PackageReference Include="CommunityToolkit.Mvvm" />
	<PackageReference Include="Microsoft.Data.SqlClient" />
	<PackageReference Include="Microsoft.Extensions.Logging.Debug" />
	<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" />
	<PackageReference Include="Microsoft.Maui.Controls" />
	<PackageReference Include="Microsoft.Maui.Controls.Compatibility" />
	<PackageReference Include="Serilog.Sinks.Debug" />
	<PackageReference Include="Telerik.UI.for.Maui" />
	<PackageReference Include="Xamarin.AndroidX.Activity" />
	<PackageReference Include="Xamarin.AndroidX.Activity.Ktx" />
	<PackageReference Include="Xamarin.AndroidX.Preference" />
	<PackageReference Include="Xamarin.Google.Android.Material" />
</ItemGroup>

I'm getting NU1008 error : Projects that use central package version management should not define the version on the PackageReference items but on the PackageVersion items: PackageId.

Maybe I'm missing a little something inside my .csproj !

Edit : My Directory.Packages.props is used by other desktop projects without any issue

@jonathanpeppers

Copy link
Copy Markdown
Member Author

The error says you have a <PackageReference ... Version="..." /> somewhere. A .binlog (https://aka.ms/binlog) would help you easily find where if the error message doesn't show a file and line number.

@LeDahu22

Copy link
Copy Markdown

Hi @jonathanpeppers,
Thanks a lot for pointing the binlog solution ! Using MSBuild Structured Log Viewer, I was able to identify the real issue : I was missing Microsoft.Maui.Controls.Compatibility in my Directory.Packages.props (which VS never mentionned)

@jonathanpeppers

Copy link
Copy Markdown
Member Author

One of the downfalls of CPM, is they have no way to give a line number where the item group is... It's just an MSBuild item group and it's not currently possible in an MSBuild task to find the line number an item originated from.

@LeDahu22

Copy link
Copy Markdown

At least the binlog viewer is useful for this ! Thank you for your help

@github-actions github-actions Bot locked and limited conversation to collaborators Dec 31, 2023
@samhouts samhouts added the fixed-in-8.0.0-rc.2.9373 Look for this fix in 8.0.0-rc.2.9373! label Aug 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-infrastructure CI, Maestro / Coherency, upstream dependencies/versions area-single-project Splash Screen, Multi-Targeting, MauiFont, MauiImage, MauiAsset, Resizetizer fixed-in-8.0.0-rc.2.9373 Look for this fix in 8.0.0-rc.2.9373!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Using central package management causes build breaking NU1009 with MAUI projects

8 participants