From 97e8329a88ba92bd0ad8879efaf569ec56a80e0a Mon Sep 17 00:00:00 2001 From: Bluehill / Jonghyo Lee Date: Thu, 22 Feb 2024 08:33:07 +0900 Subject: [PATCH] NuGet: Set EnableWindowsTargeting as true (#9082) * Set EnableWindowsTargeting * Revert "Set EnableWindowsTargeting" This reverts commit b45ddf5ce16dc56a059aecd0e09cdcf2a433ecb4. * Add EnableWindowsTargeting in temp project * Add Test case --------- Co-authored-by: AbdulFattaah Popoola Co-authored-by: Nish Sinha --- .../Update/UpdateWorkerTests.Sdk.cs | 32 +++++++++++++++++++ .../Utilities/MSBuildHelper.cs | 12 ++++++- 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTests.Sdk.cs b/nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTests.Sdk.cs index 4dea5d289c2..220a62a8677 100644 --- a/nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTests.Sdk.cs +++ b/nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTests.Sdk.cs @@ -50,6 +50,38 @@ public async Task UpdateVersionAttribute_InProjectFile_ForPackageReferenceInclud """); } + [Fact] + public async Task UpdateVersionAttribute_InProjectFile_ForPackageReferenceInclude_Windows() + { + // update Newtonsoft.Json from 9.0.1 to 13.0.1 + await TestUpdateForProject("Newtonsoft.Json", "9.0.1", "13.0.1", + // initial + projectContents: $""" + + + net8.0-windows10.0.19041.0 + win-x64 + + + + + + + """, + // expected + expectedProjectContents: $""" + + + net8.0-windows10.0.19041.0 + win-x64 + + + + + + + """); + } [Theory] [InlineData("$(NewtonsoftJsonVersion")] diff --git a/nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/MSBuildHelper.cs b/nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/MSBuildHelper.cs index 2fb64bfc5b2..e6e0fd241c5 100644 --- a/nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/MSBuildHelper.cs +++ b/nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/MSBuildHelper.cs @@ -360,7 +360,17 @@ private static ProjectRootElement CreateProjectRootElement(ProjectBuildFile buil await File.WriteAllTextAsync(tempProjectPath, projectContents); // prevent directory crawling - await File.WriteAllTextAsync(Path.Combine(tempDir.FullName, "Directory.Build.props"), ""); + await File.WriteAllTextAsync( + Path.Combine(tempDir.FullName, "Directory.Build.props"), + """ + + + + true + + + """); + await File.WriteAllTextAsync(Path.Combine(tempDir.FullName, "Directory.Build.targets"), ""); await File.WriteAllTextAsync(Path.Combine(tempDir.FullName, "Directory.Packages.props"), "");