Skip to content

Commit 3af5ec0

Browse files
nkolev92Copilot
andauthored
Add extra parameter to get nearest (#12932)
Fixes # ### Context Design: NuGet/Home#12124 To allow duplicate frameworks in aliasing, the project reference protocol nearest framework selection needs to be updated to support matching by alias as well. Relevant part: https://github.com/NuGet/Home/blob/dev-nkolev92-tfmaliases/accepted/2025/Multiple-Equivalent-Framework-Support-TFM-As-Aliases.md#project-to-project-references NuGet/NuGet.Client#7011 NuGet.Client side adding the parameter. NuGet/NuGet.Client#6972 will add the full implementation at a later point. ### Changes Made - Pass CurrentProjectTargetFrameworkProperty if GetReferenceNearestTargetFrameworkTaskSupportsTargetFrameworKPropertyParameter is set. - If GetReferenceNearestTargetFrameworkTaskSupportsTargetFrameworKPropertyParameter is not set, but GetReferenceNearestTargetFrameworkTaskSupportsTargetPlatformParameter is set, call the old variation. - Otherwise calls the last variation. ### Testing - Manual testing. - I'd be happy to add tests if someone can point me in the right direction. ### Notes The idea here is to get ahead of things. Currently aliasing work can't be end to end tested because it requires an msbuild change. It makes it really hard to validate the NuGet changes are enough and good, but this is the only change needed on the msbuild side. --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 9263fe6 commit 3af5ec0

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

documentation/ProjectReference-Protocol.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ If implementing a project with an “outer” (determine what properties to pass
6161
* `Platforms` indicating what platforms are available for the project to build as, and boolean metadata `IsVcxOrNativeProj` (used for [SetPlatform Negotiation](#setplatform-negotiation))
6262
* The `GetReferenceNearestTargetFrameworkTask` (provided by NuGet) is responsible for selecting the best matching `TargetFramework` of the referenced project
6363
* This target is _optional_. If not present, the reference will be built with no additional properties.
64-
* **New** in MSBuild 15.5. (`TargetFrameworkMonikers` and `TargetPlatformMonikers` metadata is new in MSBuild 16.8)
64+
* **New** in MSBuild 15.5. (`TargetFrameworkMonikers` and `TargetPlatformMonikers` metadata is new in MSBuild 16.8, `TargetFramework` metadata is new in MSBuild 18.3)
6565
* It is possible to gather additional information from referenced projects. See the below section on "Getting additional properties from referenced projects" for more information
6666
* `GetTargetFrameworkProperties` determines what properties should be passed to the “main” target for a given `ReferringTargetFramework`.
6767
* **Deprecated** in MSBuild 15.5.

src/Tasks/Microsoft.Common.CurrentVersion.targets

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1883,16 +1883,30 @@ Copyright (C) Microsoft Corporation. All rights reserved.
18831883

18841884
<!-- For each reference, get closest match -->
18851885

1886-
<!-- Pass the CurrentProjectTargetPlatform parameter to the task only if GetReferenceNearestTargetFrameworkTaskSupportsTargetPlatformParameter is true. This means
1886+
<!-- Pass the CurrentProjectTargetFrameworkProperty parameter to the task only if GetReferenceNearestTargetFrameworkTaskSupportsTargetFrameworkPropertyParameter is true. This means
18871887
that we are using a version of NuGet which supports that parameter on this task. -->
18881888

18891889
<GetReferenceNearestTargetFrameworkTask AnnotatedProjectReferences="@(_ProjectReferenceTargetFrameworkPossibilities)"
18901890
CurrentProjectTargetFramework="$(ReferringTargetFrameworkForProjectReferences)"
18911891
CurrentProjectTargetPlatform="$(TargetPlatformMoniker)"
1892+
CurrentProjectTargetFrameworkProperty="$(TargetFramework)"
18921893
CurrentProjectName="$(MSBuildProjectName)"
18931894
FallbackTargetFrameworks="$(AssetTargetFallback)"
18941895
Condition="'@(_ProjectReferenceTargetFrameworkPossibilities)' != '' and '$(ReferringTargetFrameworkForProjectReferences)' != ''
1895-
And '$(GetReferenceNearestTargetFrameworkTaskSupportsTargetPlatformParameter)' == 'true' and '%(_ProjectReferenceTargetFrameworkPossibilities.IsVcxOrNativeProj)' != 'true'">
1896+
And '$(GetReferenceNearestTargetFrameworkTaskSupportsTargetFrameworkPropertyParameter)' == 'true' and '%(_ProjectReferenceTargetFrameworkPossibilities.IsVcxOrNativeProj)' != 'true'">
1897+
<Output ItemName="AnnotatedProjects" TaskParameter="AssignedProjects" />
1898+
</GetReferenceNearestTargetFrameworkTask>
1899+
1900+
<!-- Pass the CurrentProjectTargetPlatform parameter to the task only if GetReferenceNearestTargetFrameworkTaskSupportsTargetPlatformParameter is true and GetReferenceNearestTargetFrameworkTaskSupportsTargetFrameworkPropertyParameter is not true. This means
1901+
that we are using a version of NuGet which supports that parameter on this task. -->
1902+
1903+
<GetReferenceNearestTargetFrameworkTask AnnotatedProjectReferences="@(_ProjectReferenceTargetFrameworkPossibilities)"
1904+
CurrentProjectTargetFramework="$(ReferringTargetFrameworkForProjectReferences)"
1905+
CurrentProjectTargetPlatform="$(TargetPlatformMoniker)"
1906+
CurrentProjectName="$(MSBuildProjectName)"
1907+
FallbackTargetFrameworks="$(AssetTargetFallback)"
1908+
Condition="'@(_ProjectReferenceTargetFrameworkPossibilities)' != '' and '$(ReferringTargetFrameworkForProjectReferences)' != ''
1909+
And '$(GetReferenceNearestTargetFrameworkTaskSupportsTargetPlatformParameter)' == 'true' and '$(GetReferenceNearestTargetFrameworkTaskSupportsTargetFrameworkPropertyParameter)' != 'true' and '%(_ProjectReferenceTargetFrameworkPossibilities.IsVcxOrNativeProj)' != 'true'">
18961910
<Output ItemName="AnnotatedProjects" TaskParameter="AssignedProjects" />
18971911
</GetReferenceNearestTargetFrameworkTask>
18981912

0 commit comments

Comments
 (0)