Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support both Update and Include for maui #14576

Closed
wants to merge 12 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/Templates/tests/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
<Project>

<PropertyGroup>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,26 @@ public void PackCoreLib(string id, string framework, string config)
$"Project {Path.GetFileName(projectFile)} failed to build. Check test output/attachments for errors.");
}

[Test]
[TestCase("maui", "net7.0", "Debug", "Update")]
[TestCase("maui", "net7.0", "Debug", "Include")]
public void BuildWithPackageReference(string id, string framework, string config, string type)
{
var projectDir = TestDirectory;
var projectFile = Path.Combine(projectDir, $"{Path.GetFileName(projectDir)}.csproj");

Assert.IsTrue(DotnetInternal.New(id, projectDir, framework),
$"Unable to create template {id}. Check test output for errors.");

EnableTizen(projectFile);
FileUtilities.ReplaceInFile(projectFile,
"</Project>",
"<ItemGroup><PackageRefernce " + type + "=\"Microsoft.Maui.Controls\" Version=\"$(MauiVersion)\" /></ItemGroup></Project>");

Assert.IsTrue(DotnetInternal.Build(projectFile, config, properties: BuildProps),
$"Project {Path.GetFileName(projectFile)} failed to build. Check test output/attachments for errors.");
}

void EnableTizen(string projectFile)
{
FileUtilities.ReplaceInFile(projectFile, new Dictionary<string, string>()
Expand Down
60 changes: 28 additions & 32 deletions src/Workload/Microsoft.Maui.Sdk/Microsoft.Maui.Sdk.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,38 +36,6 @@
DependsOnTargets="SetVersions"
Inputs="$(MSBuildProjectFile);$(MauiRootDirectory)eng/Versions.props;Sdk/BundledVersions.in.targets"
Outputs="$(IntermediateOutputPath)BundledVersions.targets">
<XmlPeek
XmlInputPath="$(MauiRootDirectory)eng\AndroidX.targets"
Query="/Project/ItemGroup/PackageReference[@Update='Xamarin.AndroidX.Browser']/@Version">
<Output TaskParameter="Result" PropertyName="_XamarinAndroidXBrowserVersion" />
</XmlPeek>
<XmlPeek
XmlInputPath="$(MauiRootDirectory)eng\AndroidX.targets"
Query="/Project/ItemGroup/PackageReference[@Update='Xamarin.AndroidX.SwipeRefreshLayout']/@Version">
<Output TaskParameter="Result" PropertyName="_XamarinAndroidXSwipeRefreshLayoutVersion" />
</XmlPeek>
<XmlPeek
XmlInputPath="$(MauiRootDirectory)eng\AndroidX.targets"
Query="/Project/ItemGroup/PackageReference[@Update='Xamarin.AndroidX.Lifecycle.LiveData']/@Version">
<Output TaskParameter="Result" PropertyName="_XamarinAndroidXLifecycleLiveDataVersion" />
</XmlPeek>
<XmlPeek
XmlInputPath="$(MauiRootDirectory)eng\AndroidX.targets"
Query="/Project/ItemGroup/PackageReference[@Update='Xamarin.AndroidX.Navigation.UI']/@Version">
<Output TaskParameter="Result" PropertyName="_XamarinAndroidXNavigationVersion" />
</XmlPeek>
<XmlPeek
XmlInputPath="$(MauiRootDirectory)eng\AndroidX.targets"
Query="/Project/ItemGroup/PackageReference[@Update='Xamarin.Google.Android.Material']/@Version">
<Output TaskParameter="Result" PropertyName="_XamarinGoogleAndroidMaterialVersion" />
</XmlPeek>
<ItemGroup>
<_ValuesToReplace Include="_XamarinAndroidXBrowserVersion" PropertyName="_XamarinAndroidXBrowserVersion" />
<_ValuesToReplace Include="_XamarinAndroidXSwipeRefreshLayoutVersion" PropertyName="_XamarinAndroidXSwipeRefreshLayoutVersion" />
<_ValuesToReplace Include="_XamarinAndroidXLifecycleLiveDataVersion" PropertyName="_XamarinAndroidXLifecycleLiveDataVersion" />
<_ValuesToReplace Include="_XamarinAndroidXNavigationVersion" PropertyName="_XamarinAndroidXNavigationVersion" />
<_ValuesToReplace Include="_XamarinGoogleAndroidMaterialVersion" PropertyName="_XamarinGoogleAndroidMaterialVersion" />
</ItemGroup>
<Copy
SourceFiles="Sdk/BundledVersions.in.targets"
DestinationFiles="$(IntermediateOutputPath)BundledVersions.targets"
Expand All @@ -91,4 +59,32 @@
</ItemGroup>
</Target>

<Target Name="_GenerateAutoImport"
BeforeTargets="Build;AssignTargetPaths"
DependsOnTargets="SetVersions"
Inputs="$(MSBuildProjectFile);$(MauiRootDirectory)eng/Versions.props;Sdk/AutoImport.in.props"
Outputs="$(IntermediateOutputPath)AutoImport.props">
<Copy
SourceFiles="Sdk/AutoImport.in.props"
DestinationFiles="$(IntermediateOutputPath)AutoImport.props"
/>
<ReplaceText
Input="$(IntermediateOutputPath)AutoImport.props"
Output="$(IntermediateOutputPath)AutoImport.props"
OldValue="@%(_ValuesToReplace.Identity)@"
NewValue="$(%(_ValuesToReplace.PropertyName))"
/>
<ItemGroup>
<None
Include="$(IntermediateOutputPath)AutoImport.props"
Link="Sdk/AutoImport.props"
CopyToOutputDirectory="PreserveNewest"
Pack="true"
PackagePath="Sdk"
Visible="false"
/>
<FileWrites Include="$(IntermediateOutputPath)AutoImport.props" />
</ItemGroup>
</Target>

</Project>
39 changes: 39 additions & 0 deletions src/Workload/Microsoft.Maui.Sdk/Sdk/AutoImport.in.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<Project>

<!--
These implicit <PackageReference/> pull dependencies from NuGet transitively.
They are first added to the <_MauiImplicitPackageReference/> item group to list the the desired
packages. Then the implicit packages are added into the project, exclding any duplicate
packages added via the projet or user props.

This logic only installs packages if and only if $(UseMauiNuGets) is not true. This property
allows the user to totally override all the default nugets installed.

These are imported in the AutoImport.props because the IDE now no longer adds packages with
just the "Include" attribute, but also with "Update". As a result, we need to first add all
the packages we want and let the IDE/user Update OR Include the same ones. We will remove
our duplicates later in BundledVersions.targets.
-->
<ItemGroup Condition=" '$(EnableMauiImplicitPackageReferences)' != 'false' and '$(UseMauiNuGets)' != 'true' and '$(TargetFrameworkIdentifier)' == '.NETCoreApp' and '$(TargetFrameworkVersion)' != '' and $([MSBuild]::VersionEquals('$(TargetFrameworkVersion)', '@MAUI_DOTNET_VERSION@')) ">
<_MauiImplicitPackageReference Include="Microsoft.Maui.Resizetizer" Version="$(MauiVersion)" PrivateAssets="all" Condition=" '$(UseMauiAssets)' == 'true' " />
<_MauiImplicitPackageReference Include="Microsoft.Maui.Essentials" Version="$(MauiVersion)" Condition=" '$(UseMauiEssentials)' == 'true' ">
<PrivateAssets Condition=" '$(OutputType)' == 'Library' and '$(AndroidApplication)' != 'true' ">all</PrivateAssets>
</_MauiImplicitPackageReference>
<_MauiImplicitPackageReference Include="Microsoft.Maui.Core" Version="$(MauiVersion)" Condition=" '$(UseMauiCore)' == 'true' ">
<PrivateAssets Condition=" '$(OutputType)' == 'Library' and '$(AndroidApplication)' != 'true' ">all</PrivateAssets>
</_MauiImplicitPackageReference>
<_MauiImplicitPackageReference Include="Microsoft.Maui.Controls" Version="$(MauiVersion)" Condition=" '$(UseMaui)' == 'true' ">
<PrivateAssets Condition=" '$(OutputType)' == 'Library' and '$(AndroidApplication)' != 'true' ">all</PrivateAssets>
</_MauiImplicitPackageReference>
<_MauiImplicitPackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="$(MauiVersion)" Condition=" '$(UseMaui)' == 'true' and '$(UseMauiCompat)' == 'true' ">
<PrivateAssets Condition=" '$(OutputType)' == 'Library' and '$(AndroidApplication)' != 'true' ">all</PrivateAssets>
</_MauiImplicitPackageReference>
<_MauiImplicitPackageReference Include="Microsoft.AspNetCore.Components.WebView.Maui" Version="$(MauiVersion)" Condition=" '$(UseMaui)' == 'true' and '$(UsingMicrosoftNETSdkRazor)' == 'true' ">
<PrivateAssets Condition=" '$(OutputType)' == 'Library' and '$(AndroidApplication)' != 'true' ">all</PrivateAssets>
</_MauiImplicitPackageReference>
</ItemGroup>
<ItemGroup Condition=" '$(EnableMauiImplicitPackageReferences)' != 'false' and '$(UseMauiNuGets)' != 'true' ">
<PackageReference Include="@(_MauiImplicitPackageReference)" Exclude="@(PackageReference)" IsMauiImplicitPackageReference="true" />
</ItemGroup>

</Project>
1 change: 0 additions & 1 deletion src/Workload/Microsoft.Maui.Sdk/Sdk/AutoImport.props

This file was deleted.

66 changes: 19 additions & 47 deletions src/Workload/Microsoft.Maui.Sdk/Sdk/BundledVersions.in.targets
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
<PropertyGroup>
<MauiWorkloadVersion>@VERSION@</MauiWorkloadVersion>
<MauiWorkloadTargetFramework>@TFM@</MauiWorkloadTargetFramework>
<MauiWorkloadTargetFrameworkVersion>@MAUI_DOTNET_VERSION@</MauiWorkloadTargetFrameworkVersion>
<MauiVersion Condition=" '$(MauiVersion)' == '' ">$(MauiWorkloadVersion)</MauiVersion>

<!--
<!--
Indicates that the Microsoft.Maui.Controls.Compatibility package should be implicitly
referenced. This will eventually switch to false by default and become opt, in,
however Visual Studio currently depends on this assembly being loaded for Live Visual Tree.
Expand All @@ -14,54 +15,25 @@
</PropertyGroup>

<!--
These implicit <PackageReference/> pull dependencies from NuGet transitively.
They are first added to the <_MauiImplicitPackageReference/> item group to list the the desired
packages. Then the packages that were specified by the user are removed from the list. Finally,
the remaining implicit packages are added into the project.
After both the implicit packages and the user/project packages are added, we need to
remove any duplicates that we have added. In older versions of the IDE, the package manager
only supported Include so we could check here, however it now supports Update so we need to
make sure they are already available to be updated.

But the issue comes in if the user is on an existing project - or likes to use Include. In
these instances, we need to now remove out implicit packages.

This logic only installs packages if and only if $(UseMauiNuGets) is not true. This property
allows the user to totally override all the default nugets installed. This should not be needed
as the $(MauiVersion) should be sufficient. However, there may be a case to test various CI builds
of .NET MAUI. One exception the this is that the <_MauiRequiredImplicitPackageReference/> item
group is always installed as this is not maui dependencies but rather .NET support dependencies.
allows the user to totally override all the default nugets installed.
-->
<ItemGroup Condition=" '$(UseMauiAssets)' == 'true' ">
<_MauiImplicitPackageReference Include="Microsoft.Maui.Resizetizer" Version="$(MauiVersion)" PrivateAssets="all" />
</ItemGroup>
<ItemGroup Condition=" '$(UseMauiEssentials)' == 'true' ">
<_MauiImplicitPackageReference Include="Microsoft.Maui.Essentials" Version="$(MauiVersion)">
<PrivateAssets Condition=" '$(OutputType)' == 'Library' and '$(AndroidApplication)' != 'true' ">all</PrivateAssets>
</_MauiImplicitPackageReference>
</ItemGroup>
<ItemGroup Condition=" '$(UseMauiCore)' == 'true' ">
<_MauiImplicitPackageReference Include="Microsoft.Maui.Core" Version="$(MauiVersion)">
<PrivateAssets Condition=" '$(OutputType)' == 'Library' and '$(AndroidApplication)' != 'true' ">all</PrivateAssets>
</_MauiImplicitPackageReference>
</ItemGroup>
<ItemGroup Condition=" '$(UseMaui)' == 'true' ">
<_MauiImplicitPackageReference Include="Microsoft.Maui.Controls" Version="$(MauiVersion)">
<PrivateAssets Condition=" '$(OutputType)' == 'Library' and '$(AndroidApplication)' != 'true' ">all</PrivateAssets>
</_MauiImplicitPackageReference>
</ItemGroup>
<ItemGroup Condition=" '$(UseMaui)' == 'true' and '$(UseMauiCompat)' == 'true' ">
<_MauiImplicitPackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="$(MauiVersion)">
<PrivateAssets Condition=" '$(OutputType)' == 'Library' and '$(AndroidApplication)' != 'true' ">all</PrivateAssets>
</_MauiImplicitPackageReference>
</ItemGroup>
<ItemGroup Condition=" '$(UseMaui)' == 'true' and '$(UsingMicrosoftNETSdkRazor)' == 'true' ">
<_MauiImplicitPackageReference Include="Microsoft.AspNetCore.Components.WebView.Maui" Version="$(MauiVersion)">
<PrivateAssets Condition=" '$(OutputType)' == 'Library' and '$(AndroidApplication)' != 'true' ">all</PrivateAssets>
</_MauiImplicitPackageReference>
</ItemGroup>
<!-- Always install the required dependecies, such as build tools for the SDK itself -->
<ItemGroup>
<_MauiRequiredImplicitPackageReference Remove="@(PackageReference)" />
<PackageReference Include="@(_MauiRequiredImplicitPackageReference)" />
</ItemGroup>
<!-- Install the nuget packages if we are supposed to -->
<ItemGroup Condition=" '$(UseMauiNuGets)' != 'true' ">
<_MauiImplicitPackageReference Remove="@(PackageReference)" />
<PackageReference Include="@(_MauiImplicitPackageReference)" />
<ItemGroup Condition=" '$(EnableMauiImplicitPackageReferences)' != 'false' and '$(UseMauiNuGets)' != 'true' ">
<_MauiAddedImplicitMauiPackageReference Include="@(PackageReference->HasMetadata('IsMauiImplicitPackageReference'))" />
<_MauiAddedUserNonMauiPackageReference Include="@(PackageReference)" Exclude="@(_MauiAddedImplicitMauiPackageReference)" />
<_MauiAddedUserAllPackageReference Include="@(PackageReference->WithMetadataValue('IsMauiImplicitPackageReference',''))" />
<_MauiAddedUserMauiPackageReference Include="@(_MauiAddedUserAllPackageReference)" Exclude="@(_MauiAddedUserNonMauiPackageReference)" />
<PackageReference Remove="@(_MauiAddedImplicitMauiPackageReference)" /> <!-- this also removes Microsoft.Maui.* packages from the csproj -->
<PackageReference Include="@(_MauiAddedUserMauiPackageReference)" /> <!-- so we have to add it back -->
<PackageReference Include="@(_MauiAddedImplicitMauiPackageReference)" Exclude="@(PackageReference)" /> <!-- and then add missing implicit packages -->
</ItemGroup>

</Project>
</Project>