From 514d6a9b7638bacf58672b4cdf1ee0389f22133b Mon Sep 17 00:00:00 2001 From: "Brett V. Forsgren" Date: Mon, 3 Mar 2025 11:31:55 -0700 Subject: [PATCH] use different values for `$(TargetPlatformVersion)` for TFM and dependency discovery --- .../Discover/SdkProjectDiscoveryTests.cs | 45 +++++++++++++++++++ .../Utilities/MSBuildHelperTests.cs | 12 +++++ .../DependencyDiscovery.props | 10 ++++- .../DependencyDiscovery.targets | 5 +++ 4 files changed, 71 insertions(+), 1 deletion(-) diff --git a/nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Discover/SdkProjectDiscoveryTests.cs b/nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Discover/SdkProjectDiscoveryTests.cs index 90f03bed81b..a437da0414e 100644 --- a/nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Discover/SdkProjectDiscoveryTests.cs +++ b/nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Discover/SdkProjectDiscoveryTests.cs @@ -479,6 +479,51 @@ await TestDiscoverAsync( ); } + [Fact] + public async Task DependenciesCanBeDiscoveredWithWindowsSpecificTfm() + { + await TestDiscoverAsync( + packages: + [ + MockNuGetPackage.CreateSimplePackage("Some.Dependency", "1.2.3", "netstandard2.0"), + ], + startingDirectory: "src", + projectPath: "src/library.csproj", + files: + [ + ("src/library.csproj", """ + + + net9.0-windows + + + + + + """) + ], + expectedProjects: + [ + new() + { + FilePath = "library.csproj", + Dependencies = + [ + new("Some.Dependency", "1.2.3", DependencyType.PackageReference, TargetFrameworks: ["net9.0-windows"], IsDirect: true), + ], + ImportedFiles = [], + Properties = + [ + new("TargetFramework", "net9.0-windows", "src/library.csproj"), + ], + TargetFrameworks = ["net9.0-windows"], + ReferencedProjectPaths = [], + AdditionalFiles = [], + }, + ] + ); + } + private static async Task TestDiscoverAsync(string startingDirectory, string projectPath, TestFile[] files, ImmutableArray expectedProjects, MockNuGetPackage[]? packages = null) { using var testDirectory = await TemporaryDirectory.CreateWithContentsAsync(files); diff --git a/nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Utilities/MSBuildHelperTests.cs b/nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Utilities/MSBuildHelperTests.cs index cc261755fc8..3d2d5a08596 100644 --- a/nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Utilities/MSBuildHelperTests.cs +++ b/nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Utilities/MSBuildHelperTests.cs @@ -606,6 +606,18 @@ public static IEnumerable GetTargetFrameworkValuesFromProjectData() new[] { "net8.0-windows7.0" } ]; + yield return + [ + """ + + + net9.0-windows + + + """, + new[] { "net9.0-windows" } + ]; + // legacy projects yield return [ diff --git a/nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core/DependencyDiscovery.props b/nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core/DependencyDiscovery.props index cec5322a187..decaca93d19 100644 --- a/nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core/DependencyDiscovery.props +++ b/nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core/DependencyDiscovery.props @@ -1,8 +1,16 @@ + + <_DefaultTargetPlatformVersion Condition="'$(_DefaultTargetPlatformVersion)' == ''">0.0 true true - 1.0 + $(_DefaultTargetPlatformVersion) \ No newline at end of file diff --git a/nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core/DependencyDiscovery.targets b/nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core/DependencyDiscovery.targets index 65ba7d4bbd7..10237b0e632 100644 --- a/nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core/DependencyDiscovery.targets +++ b/nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core/DependencyDiscovery.targets @@ -1,4 +1,9 @@ + + + <_DefaultTargetPlatformVersion>1.0 + +