Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Draft
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
20 changes: 17 additions & 3 deletions src/msbuild/src/Tasks/Microsoft.Common.CurrentVersion.targets
Original file line number Diff line number Diff line change
Expand Up @@ -1883,16 +1883,30 @@ Copyright (C) Microsoft Corporation. All rights reserved.

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

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

<GetReferenceNearestTargetFrameworkTask AnnotatedProjectReferences="@(_ProjectReferenceTargetFrameworkPossibilities)"
CurrentProjectTargetFramework="$(ReferringTargetFrameworkForProjectReferences)"
CurrentProjectTargetPlatform="$(TargetPlatformMoniker)"
CurrentProjectTargetFrameworkProperty="$(TargetFramework)"
Copy link
Member

Choose a reason for hiding this comment

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

Would you mind describing the difference between this parameter and the CurrentProjectTargetFramework one?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

CurrentProjectTargetFramework is the TargetFrameworkMoniker
CurrentProjectTargetFrameworkProperty is the TargetFramework property itself

CurrentProjectName="$(MSBuildProjectName)"
FallbackTargetFrameworks="$(AssetTargetFallback)"
Condition="'@(_ProjectReferenceTargetFrameworkPossibilities)' != '' and '$(ReferringTargetFrameworkForProjectReferences)' != ''
And '$(GetReferenceNearestTargetFrameworkTaskSupportsTargetPlatformParameter)' == 'true' and '%(_ProjectReferenceTargetFrameworkPossibilities.IsVcxOrNativeProj)' != 'true'">
And '$(GetReferenceNearestTargetFrameworkTaskSupportsTargetFrameworkPropertyParameter)' == 'true' and '%(_ProjectReferenceTargetFrameworkPossibilities.IsVcxOrNativeProj)' != 'true'">
<Output ItemName="AnnotatedProjects" TaskParameter="AssignedProjects" />
</GetReferenceNearestTargetFrameworkTask>

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

<GetReferenceNearestTargetFrameworkTask AnnotatedProjectReferences="@(_ProjectReferenceTargetFrameworkPossibilities)"
CurrentProjectTargetFramework="$(ReferringTargetFrameworkForProjectReferences)"
CurrentProjectTargetPlatform="$(TargetPlatformMoniker)"
CurrentProjectName="$(MSBuildProjectName)"
FallbackTargetFrameworks="$(AssetTargetFallback)"
Condition="'@(_ProjectReferenceTargetFrameworkPossibilities)' != '' and '$(ReferringTargetFrameworkForProjectReferences)' != ''
And '$(GetReferenceNearestTargetFrameworkTaskSupportsTargetPlatformParameter)' == 'true' and '$(GetReferenceNearestTargetFrameworkTaskSupportsTargetFrameworkPropertyParameter)' != 'true' and '%(_ProjectReferenceTargetFrameworkPossibilities.IsVcxOrNativeProj)' != 'true'">
<Output ItemName="AnnotatedProjects" TaskParameter="AssignedProjects" />
</GetReferenceNearestTargetFrameworkTask>

Expand Down Expand Up @@ -7032,4 +7046,4 @@ Copyright (C) Microsoft Corporation. All rights reserved.

<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.targets\ImportAfter\*" Condition="'$(ImportByWildcardAfterMicrosoftCommonTargets)' == 'true' and exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.targets\ImportAfter')"/>
<Import Project="$(MSBuildUserExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.targets\ImportAfter\*" Condition="'$(ImportUserLocationsByWildcardAfterMicrosoftCommonTargets)' == 'true' and exists('$(MSBuildUserExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.targets\ImportAfter')"/>
</Project>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
using NuGet.Common;
using NuGet.Frameworks;

#if NETFRAMEWORK || NETSTANDARD
#if NETFRAMEWORK
using System.Linq;
#endif

namespace NuGet.Build.Tasks
{
public class GetReferenceNearestTargetFrameworkTask : Microsoft.Build.Utilities.Task
public class GetReferenceNearestTargetFrameworkTask : Task
{
private const string NEAREST_TARGET_FRAMEWORK = "NearestTargetFramework";
private const string TARGET_FRAMEWORKS = "TargetFrameworks";
Expand All @@ -41,6 +41,11 @@ public class GetReferenceNearestTargetFrameworkTask : Microsoft.Build.Utilities.
/// </summary>
public string CurrentProjectTargetPlatform { get; set; }

/// <summary>
/// The value of the current project's TargetFramework property.
/// </summary>
public string CurrentProjectTargetFrameworkProperty { get; set; }

/// <summary>
/// Optional list of target frameworks to be used as Fallback target frameworks.
/// </summary>
Expand Down Expand Up @@ -147,7 +152,6 @@ private ITaskItem AssignNearestFrameworkForSingleReference(
useTargetMonikers ? referencedProjectTargetPlatformMonikers[i] : null));
}

// try project framework
var nearestNuGetFramework = NuGetFrameworkUtility.GetNearest(targetFrameworkInformations, projectNuGetFramework, GetNuGetFramework);
if (nearestNuGetFramework != null)
{
Expand Down Expand Up @@ -252,4 +256,4 @@ public TargetFrameworkInformation(string targetFrameworkAlias, string targetFram
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ Copyright (c) .NET Foundation. All rights reserved.
<PackageDownloadSupported>true</PackageDownloadSupported>
<!-- Mark that this targets file GetReferenceNearestTargetFrameworkTask task supports the TargetPlatformMoniker -->
<GetReferenceNearestTargetFrameworkTaskSupportsTargetPlatformParameter>true</GetReferenceNearestTargetFrameworkTaskSupportsTargetPlatformParameter>
<!-- Mark that this targets file GetReferenceNearestTargetFrameworkTask task supports the TargetFramework -->
<GetReferenceNearestTargetFrameworkTaskSupportsTargetFrameworkPropertyParameter>true</GetReferenceNearestTargetFrameworkTaskSupportsTargetFrameworkPropertyParameter>
<!-- Flag if the Central package file is enabled -->
<_CentralPackageVersionsEnabled Condition="'$(ManagePackageVersionsCentrally)' == 'true' AND '$(CentralPackageVersionsFileImported)' == 'true'">true</_CentralPackageVersionsEnabled>
</PropertyGroup>
Expand Down Expand Up @@ -1577,4 +1579,4 @@ Copyright (c) .NET Foundation. All rights reserved.
-->
<Import Project="NuGet.RestoreEx.targets" Condition="'$(RestoreUseStaticGraphEvaluation)' == 'true' And Exists('NuGet.RestoreEx.targets')" />

</Project>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,11 @@ public void GetReferenceNearestTargetFrameworkTask_WithSingleTfmAndSingleAtfAndN
[InlineData(".NETCoreApp,Version=v5.0", "Windows,Version=7.0", "net5.0-windows;netcoreapp3.1", ".NETCoreApp,Version=v5.0;.NETCoreApp,Version=v3.1", "Windows,Version=7.0;Windows,Version=7.0", "net5.0-windows")]
[InlineData(".NETCoreApp,Version=v5.0", "None", "net;net-windows", ".NETCoreApp,Version=v5.0;.NETCoreApp,Version=v5.0", "None;Windows,Version=7.0", "net")]
[InlineData(".NETCoreApp,Version=v3.1", "Windows,Version=7.0", "net50;netstandard20", ".NETCoreApp,Version=v5.0;NETStandard,Version=v2.0", "Windows,Version=7.0;None", "netstandard20")]
[InlineData(".NETCoreApp,Version=v10.0", null, // TFM & TPM of current project
"apple;netstandard20", // TargetFramework of reference project
".NETCoreApp,Version=v5.0;NETStandard,Version=v2.0", // TFM of reference project
"Windows,Version=7.0;None", // TPM of reference project
"netstandard20")] // Alias to return
public void GetReferenceNearestTargetFrameworkTask_WithTargetFrameworkInformation_ReturnsCompatibleAlias(
string currentProjectTFM, string currentProjectTPM, string refTargetFrameworks, string refTargetFrameworkMonikers, string refTargetPlatformMonikers, string expected)
{
Expand Down Expand Up @@ -535,7 +540,6 @@ public void GetReferenceNearestTargetFrameworkTask_WithTargetFrameworkInformatio
testLogger.Errors.Should().Be(1);
}


[Theory]
[InlineData(".NETFramework,Version=v4.7.2", null, "net46;net472", ".NETFramework,Version=v4.6", "None")]
[InlineData(".NETFramework,Version=v4.7.2", null, "net46", ".NETFramework,Version=v4.6;.NETFramework,Version=v4.7.2", "None")]
Expand Down Expand Up @@ -647,4 +651,4 @@ public void GetReferenceNearestTargetFrameworkTask_WithTargetFrameworkInformatio
testLogger.Errors.Should().Be(0);
}
}
}
}