Skip to content

Match in-tree order of targets with workloads and fix some WinUI issues#5923

Merged
mattleibow merged 9 commits intomainfrom
dev/maui-intree
Apr 11, 2022
Merged

Match in-tree order of targets with workloads and fix some WinUI issues#5923
mattleibow merged 9 commits intomainfrom
dev/maui-intree

Conversation

@mattleibow
Copy link
Copy Markdown
Member

@mattleibow mattleibow commented Apr 8, 2022

Description of Change

The order of the props/targets in the maui repo solution don't quite match the order of the targets once the workload is installed.

This PR Fixes some things:

  • Correctly ordering the props/targets in the repo to match the installed workloads
  • Fixed the AppxManifest inclusion logic:
    • Remove the logic that skipped including AppxManifest as this cannot work because the properties that are checked come AFTER this line
    • Added logic to remove the AppxManifest when it is about to be validated/used if this is an unpackaged app
  • Fixed the SDKReference warnings/errors
    • This is a UWP feature and due to a ordering issue in the WinUI targets, the check comes before the property to remove it
    • If this is a modern WinUI app, we set the WinUISDKReference to false to instruct the WinUI targets to not include them

Details

Also fixes some poor choices in #5896
And Fixes #5881 properly

This PR tries to get even closer to this. Not an exact match as there is no way to get the AutoImport.props in the right place, but it can be simulated by adding it to the end of the .csproj. And then we can use the Directory.Build.targets to simulate after all the things are ready.

It still does not quite match, but here is the orders of things:

Workloads Maui Repo
Directory.Build.props Directory.Build.props
.nuget.g.props .nuget.g.props
AutoImport.props
.csproj .csproj
Maui.InTree.props (by .csproj)
--> AutoImport.InTree.props
Maui.Controls.props --> Maui.Controls.props
--> Maui.Controls.SingleProject.props --> --> Maui.Controls.SingleProject.props
.nuget.g.targets .nuget.g.targets
Directory.Build.targets (local)
--> Maui.InTree.targets
Maui.Controls.targets --> --> Maui.Controls.targets
Maui.Controls.DefaultItems.targets --> --> Maui.Controls.DefaultItems.targets
--> Maui.Controls.SingleProject.targets --> --> --> Maui.Controls.SingleProject.targets
Directory.Build.targets --> Directory.Build.targets (actual)

@mattleibow mattleibow requested a review from a team as a code owner April 8, 2022 19:47
@Eilon Eilon added the area-infrastructure CI, Maestro / Coherency, upstream dependencies/versions label Apr 8, 2022
@mattleibow mattleibow added t/bug Something isn't working p/0 Current heighest priority issues that we are targeting for a release. fatal labels Apr 8, 2022
@mattleibow mattleibow self-assigned this Apr 8, 2022
@mattleibow mattleibow added this to the 6.0.300-rc.2 milestone Apr 8, 2022
Comment on lines +9 to +21
<ItemDefinitionGroup>
<MauiXaml>
<SubType>Designer</SubType>
</MauiXaml>
</ItemDefinitionGroup>

<ItemGroup Condition="'$(EnableDefaultItems)'=='True' And '$(EnableDefaultXamlItems)'=='True' And '$(EnableDefaultEmbeddedResourceItems)'=='True'">
<MauiXaml Include="**\*.xaml" Exclude="$(DefaultItemExcludes);$(DefaultExcludesInProjectFolder);$(DefaultWebContentItemExcludes)"/>
</ItemGroup>

<ItemGroup Condition="'$(EnableDefaultItems)'=='True' And '$(EnableDefaultCssItems)'=='True' And '$(EnableDefaultEmbeddedResourceItems)'=='True'">
<MauiCss Include="**\*.css" Exclude="$(DefaultItemExcludes);$(DefaultExcludesInProjectFolder);$(DefaultWebContentItemExcludes)" />
</ItemGroup>
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved this in from DefaultItems.props as that was just a file in the maui repo and was confusing. Also, this chunk of stuff is in the AutoImport.props that the workload uses. This way it is all matching.

<PropertyGroup Condition=" '$(SingleProject)' == 'true' and '$([MSBuild]::GetTargetPlatformIdentifier($(TargetFramework)))' == 'windows' ">
<OutputType Condition="'$(OutputType)' == 'Exe'">WinExe</OutputType>
<EnablePreviewMsixTooling Condition="'$(EnablePreviewMsixTooling)' == '' and ('$(OutputType)' == 'Exe' or '$(OutputType)' == 'WinExe')">true</EnablePreviewMsixTooling>
<WindowsPackageType Condition=" '$(WindowsPackageType)' == '' and '$(EnablePreviewMsixTooling)' == 'true' and ('$(OutputType)' == 'Exe' or '$(OutputType)' == 'WinExe') ">MSIX</WindowsPackageType>
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be here to come before the nugets. Fixes a bug in #5896

Comment on lines +104 to +111
<Target Name="_MauiRemoveRemoveAppxManifestForUnpackaged"
Condition="'$(WindowsPackageType)' == 'None' and '@(AppxManifest)' != ''">

<ItemGroup>
<AppxManifest Remove="@(AppxManifest)" />
</ItemGroup>

</Target>
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue that #5896 fixes is when the manifest AND unpackaged is specified. That PR tried to fix it by not including the manifest, however, this is wrong because the way the PR did it was to check after the nuget had already defaulted to None and thus never included it.

Technically, this is actually an invalid state with unpackaged AND a manifest, however since we auto-include we also need to un-include. And secondly, what if this is a multi-mode project? Instead of requiring the user to do weird conditions, just not exclude it for the user.

Comment on lines -3 to +5
<Import Project="..\..\..\Maui.InTree.targets" />
<Import Project="$(MauiNuSpecDirectory)Microsoft.Maui.TestUtils.DeviceTests.Runners.targets" />
<Import Project="..\..\..\..\Directory.Build.targets" />
<Import Project="$(MauiSrcDirectory)Maui.InTree.targets" Condition=" '$(UseMaui)' != 'true' " />
<Import Project="$(_MauiBuildTasksLocation)Microsoft.Maui.TestUtils.DeviceTests.Runners.targets" />
<Import Project="$(MauiRootDirectory)Directory.Build.targets" />
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A big chunk of removing the ../ as this is terribly confusing.

<Compile Include="Properties\MapsKey.cs" Condition="Exists('Properties\MapsKey.cs')" />
</ItemGroup>

<Import Project="$(MauiSrcDirectory)Maui.InTree.props" Condition=" '$(UseMaui)' != 'true' " />
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All projects that need maui things, like xaml compilation, need to add Maui.InTree.props to the bottom of the .csproj in order to set values that are used by the nugets being imported.

Comment on lines +2 to +3
<Import Project="$(MauiSrcDirectory)Maui.InTree.targets" Condition=" '$(UseMaui)' != 'true' " />
<Import Project="$(MauiRootDirectory)Directory.Build.targets" />
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add the Maui.InTree.targets riiiight at the end of the list, but before the parent Directory.Build.targets. The only way to do this is to include the Maui.InTree.targets in a local Directory.Build.targets, and then include the parent afterwards.

Comment on lines 131 to +133
<AppxManifest
Include="$(PackageManifest)"
Condition="'$(WindowsPackageType)' != 'None' and Exists('$(PackageManifest)')" />
Condition="Exists('$(PackageManifest)')" />
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The other half of the fix in #5896 that ran before the .csproj or nugets. This means the only way to set this was via Directory.Build.props or via the CLI - which is not a valid requirement.

<OutputType Condition="'$(OutputType)' == 'Exe'">WinExe</OutputType>
<EnablePreviewMsixTooling Condition="'$(EnablePreviewMsixTooling)' == '' and ('$(OutputType)' == 'Exe' or '$(OutputType)' == 'WinExe')">true</EnablePreviewMsixTooling>
<WindowsPackageType Condition=" '$(WindowsPackageType)' == '' and '$(EnablePreviewMsixTooling)' == 'true' and ('$(OutputType)' == 'Exe' or '$(OutputType)' == 'WinExe') ">MSIX</WindowsPackageType>
<WinUISDKReferences Condition=" '$(WinUISDKReferences)' == '' and '$(EnablePreviewMsixTooling)' == 'true' and ('$(OutputType)' == 'Exe' or '$(OutputType)' == 'WinExe') ">false</WinUISDKReferences>
Copy link
Copy Markdown
Member Author

@mattleibow mattleibow Apr 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that we have the order correct, we can also properly exclude the SDKReferences items because they are not something WinUI actually needs. This is a UWP thing. This fixes #5881

@mattleibow mattleibow changed the title Match in-tree order of targets with workloads Match in-tree order of targets with workloads and fix some WinUI issues Apr 8, 2022
@Eilon
Copy link
Copy Markdown
Contributor

Eilon commented Apr 11, 2022

Works on my machine! I first built main, which failed with the gosh darn missing appxrecipe. I switched to the PR branch and it works!

@mattleibow mattleibow merged commit 87cc187 into main Apr 11, 2022
@mattleibow mattleibow deleted the dev/maui-intree branch April 11, 2022 20:19
@solomonfried
Copy link
Copy Markdown
Contributor

I am trying to publish my first MAUI app and am getting this error..
Improper project configuration: WindowsPackageType is set to None, but PublishAppxPackage is set to true.

According to these posts the issue was resolved. I created the project on September 5th on a brand new VS2022 installation.
Are there any instructions on how to update the project file to eliminate this?
Thank you.

@Eilon
Copy link
Copy Markdown
Contributor

Eilon commented Oct 7, 2022

Hi @solomonfried , can you please file a new issue with detailed steps to reproduce?

@solomonfried
Copy link
Copy Markdown
Contributor

Hi @solomonfried , can you please file a new issue with detailed steps to reproduce?

I have created an issue
#10576

Thanks

@McoreD
Copy link
Copy Markdown

McoreD commented Feb 1, 2023

As soon as I add <WindowsPackageType>None</WindowsPackageType> I cannot compile the solution anymore. I hope Microsoft fixes this.

@rmarinho
Copy link
Copy Markdown
Member

rmarinho commented Feb 1, 2023

@McoreD what's the error? Do you have spaces in your user profile?

@github-actions github-actions bot locked and limited conversation to collaborators Dec 21, 2023
@samhouts samhouts added the fixed-in-6.0.300-rc.2 Look for this fix in 6.0.300-rc.2! 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 fixed-in-6.0.300-rc.2 Look for this fix in 6.0.300-rc.2! p/0 Current heighest priority issues that we are targeting for a release. t/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Publishing an unpackaged Windows app fails by default

7 participants