Support both Update and Include for maui#14576
Conversation
|
forgot auto imports went to all the things... |
| <ItemGroup Condition=" '$(UseMauiNuGets)' != 'true' and '$(EnableMauiImplicitPackageReferences)' != 'false' and '$(TargetFrameworkVersion)' != '' and $([MSBuild]::VersionEquals('$(TargetFrameworkVersion)', '@MAUI_DOTNET_VERSION@')) "> | ||
| <PackageReference Include="@(_MauiImplicitPackageReference)" Exclude="@(PackageReference)" /> | ||
| </ItemGroup> |
There was a problem hiding this comment.
This pre-adds all the nugets that we need into the project at the top - before the csproj. This means Update will now work (thanks IDE) but causes issues if we have an Include.
| <ItemGroup Condition=" '$(UseMauiNuGets)' != 'true' "> | ||
| <_MauiImplicitPackageReference Remove="@(PackageReference)" /> | ||
| <PackageReference Include="@(_MauiImplicitPackageReference)" /> | ||
| <_MauiAddedImplicitPackageReference Include="@(PackageReference->HasMetadata('IsMauiImplicitPackageReference'))" /> | ||
| <_MauiAddedUserPackageReference Include="@(PackageReference->WithMetadataValue('IsMauiImplicitPackageReference',''))" /> | ||
| <_MauiMissingImplicitPackageReference Include="@(_MauiAddedImplicitPackageReference)" Exclude="@(_MauiAddedUserPackageReference)" /> | ||
| <PackageReference Remove="@(PackageReference)" /> | ||
| <PackageReference Include="@(_MauiAddedUserPackageReference);@(_MauiMissingImplicitPackageReference)" /> | ||
| </ItemGroup> |
There was a problem hiding this comment.
So we fix that here by removing the duplicates that we added. If a developer references a package then we can detect that as it will not have the IsMauiImplicitPackageReference metadata. This now fixes the double Includes (from us and from the csproj)
This may be the case from a previous project that is now built with this workload.
|
@dsplaisted do we think moving implicit It makes sense to me, so customers can modify the values from their |
|
One thing to think about is that older versions (not much as it may just be changed in the preview VS) that the package manager only did Include, now it does Update. Not sure if that difference is important for any other workloads. |
|
@dsplaisted @marcpopMSFT @jonathanpeppers any concerns here? |
|
Since the VS ide package manager doesn't handle conditional packagereferences correctly today, will this impact that experience some (I understand they are discussing options): NuGet/Home#4681 |
|
Not sure about the impact. This autoimports is adding a package for all tfms. Not sure if workloads can handle packages added in this way? Is there a design to allow workloads to depend in nugets? Or is the preferred way to use nugets in the csproj? We used to just add things in the targets, but now the IDE does not handle that anymore and the PM does an update package making it mostly useless. Unless the PM should revert that change and we go back to adding additional nugets via the targets? |
dsplaisted
left a comment
There was a problem hiding this comment.
I think this is worth trying, and will probably work pretty well.
| </_MauiImplicitPackageReference> | ||
| </ItemGroup> | ||
| <ItemGroup Condition=" '$(UseMauiNuGets)' != 'true' and '$(EnableMauiImplicitPackageReferences)' != 'false' and '$(TargetFrameworkVersion)' != '' and $([MSBuild]::VersionEquals('$(TargetFrameworkVersion)', '@MAUI_DOTNET_VERSION@')) "> | ||
| <PackageReference Include="@(_MauiImplicitPackageReference)" Exclude="@(PackageReference)" /> |
There was a problem hiding this comment.
I believe that instead of specifying IsMauiImplicitPackageReference on each individual item, you could set it once here instead.
Also, I don't think Exclude="@(PackageReference)" does anything here, so it's probably best to remove it for clarity.
I think that this is probably not going to be a problem here. I think the linked issue has to do with packages that are referenced for some of the target frameworks used in a project but not others. That is not normally going to be the case here, as even though the conditions do depend on the target framework version, I don't think it is common to have a Maui project multi-target to different versions of .NET (they multi-target to different platforms instead). |
|
Superseded by #14770 |
|
Actually, this will still occur for existing projects because maui will still be added via the targets and thus the PM will do an Update. |
|
Closing this for now as the correct way would be to add the package reference manually in net8. We can revisit this later if that is not pretty. |
Description of Change
In previous versions of the IDE, adding packages only supported
Includeand as a result we could check at the end and see what was added and what we needed. However, in newer versions, the IDE is now smarter and can detect that we added a package, and if it is from outside the csproj, it usesUpdate.As a result, this PR makes sure that we always add the NuGet so that newer IDEs (Update) have something to actually update, and to support older IDEs (Include) we remove those implicit packages to avoid duplicates.
This may be replaced by #14770