Support finding nearest TFM to collect assets from#18068
Conversation
c9a11f7 to
b3b5062
Compare
| Projects="@(ProjectReference)" | ||
| Projects="%(_ResolvedProjectReferencePaths.OriginalProjectReferenceItemSpec)" | ||
| BuildInParallel="true" | ||
| Properties="TargetFramework=$(TargetFramework)" | ||
| Properties="TargetFramework=%(_ResolvedProjectReferencePaths.NearestTargetFramework)" |
There was a problem hiding this comment.
One difference here is that % will "batch" the call running <MSBuild/> N times. Where before it would run it a single time passing in multiple projects.
Is that a problem?
There was a problem hiding this comment.
The only other question, is what happens if OriginalProjectReferenceItemSpec or NearestTargetFramework are blank? It seems like we should handle that case.
There was a problem hiding this comment.
For the first question, you just discovered a huge bug. Before, it would run all the projects with the same TFM - even if that project did not have or support it. The new way has a different TFM for each project. So I am thinking multiple builds is actually the correct way.
There was a problem hiding this comment.
For the second question, I will first filter out the items that are missing these values to be safe, but they should always have them.
There was a problem hiding this comment.
I think if %(OriginalProjectReferenceItemSpec) is blank it should just use %(Identity) and %(NearestTargetFramework) fall back to $(TargetFramework)?
MSBuild is so loosely typed these could randomly become blank in the future.
There was a problem hiding this comment.
Hmm, Identity is the path of the dll since the _ResolvedProjectReferencePaths item group is the result of the ResolveProjectReferences target.
There was a problem hiding this comment.
I updated the things to try and look at the resolved items, and any missing ones we use the project refs. For the TFM, we first try the nearest and if that is not found then we try the current app's TFM.
Description of Change
When building a maui app that references a maui class library with assets, only the exact match of the TFMs will be used. This PR adds support for falling back to the nearest match. The same TFM used in a project reference will also be used for the assets.
In the scenario:
Before:
After:
Implementation was based on these docs: https://github.com/dotnet/msbuild/blob/main/documentation/ProjectReference-Protocol.md