From a76cf4e5218403b57c3e5be5bbd96d08ef3a4684 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 6 Jul 2026 21:09:28 +0000 Subject: [PATCH 1/9] Initial plan From 2d4844168ef5a32d4973c7ce4dc8ba9c6e250db4 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 6 Jul 2026 21:12:28 +0000 Subject: [PATCH 2/9] Pass ExcludeRestorePackageImports as a restore global property (gated by change wave 18.9) Co-authored-by: ViktorHofer <7412651+ViktorHofer@users.noreply.github.com> --- documentation/wiki/ChangeWaves.md | 1 + src/Framework/MSBuildConstants.cs | 7 +++++++ src/MSBuild/XMake.cs | 8 ++++++++ 3 files changed, 16 insertions(+) diff --git a/documentation/wiki/ChangeWaves.md b/documentation/wiki/ChangeWaves.md index 02e5a2f2fee..a305237a731 100644 --- a/documentation/wiki/ChangeWaves.md +++ b/documentation/wiki/ChangeWaves.md @@ -32,6 +32,7 @@ Change wave checks around features will be removed in the release that accompani ### 18.9 - [GenerateResource: typed ResX data/metadata entries in Mark-of-the-Web files are now treated as untrusted and blocked with MSB3821; unblock the file (or set MSBUILDDISABLEFEATURESFROMVERSION=18.9) to restore prior behavior. ResXFileRef entries are always blocked regardless of this wave.](https://github.com/dotnet/msbuild/pull/14015) - [TaskHost named-pipe buffers default to 1 MB (was 128 KB), reducing send backpressure for large TaskHostConfiguration packets. Tunable via MSBUILDNODECONNECTIONBUFFERSIZE](https://github.com/dotnet/msbuild/pull/14094) +- [Restore passes ExcludeRestorePackageImports=true as a global property so NuGet's restore no longer triggers a second evaluation of every project.](https://github.com/dotnet/msbuild/issues/14273) ### 18.8 - [RAR task: across multiple input properties, resolve relative paths against the project directory (not the process current directory)](https://github.com/dotnet/msbuild/pull/13319) diff --git a/src/Framework/MSBuildConstants.cs b/src/Framework/MSBuildConstants.cs index 4e8e8fd29d8..51610e9e103 100644 --- a/src/Framework/MSBuildConstants.cs +++ b/src/Framework/MSBuildConstants.cs @@ -80,6 +80,13 @@ internal static class MSBuildConstants /// internal const string MSBuildIsRestoring = nameof(MSBuildIsRestoring); + /// + /// A property set during an implicit restore (/restore) or explicit restore (/t:restore) to instruct projects to exclude imports that are + /// provided by NuGet packages. NuGet passes this same global property when it re-invokes the build, so setting it up front ensures the + /// initial evaluation is reused rather than being discarded and re-evaluated. + /// + internal const string ExcludeRestorePackageImports = nameof(ExcludeRestorePackageImports); + /// /// The most current VSGeneralAssemblyVersion known to this version of MSBuild. /// diff --git a/src/MSBuild/XMake.cs b/src/MSBuild/XMake.cs index 6f29cbac80b..c194888fb0d 100644 --- a/src/MSBuild/XMake.cs +++ b/src/MSBuild/XMake.cs @@ -2064,6 +2064,14 @@ private static BuildResult ExecuteRestore(string projectFile, string toolsVersio // Add a property to indicate that a Restore is executing restoreGlobalProperties[MSBuildConstants.MSBuildIsRestoring] = bool.TrueString; + // Add the property that NuGet passes when it re-invokes the build during restore. NuGet's restore targets pass + // ExcludeRestorePackageImports=true as a global property, which normally forces a second evaluation of every project. + // Setting it up front here means the initial evaluation already matches, so it is reused instead of being discarded. + if (ChangeWaves.AreFeaturesEnabled(ChangeWaves.Wave18_9)) + { + restoreGlobalProperties[MSBuildConstants.ExcludeRestorePackageImports] = bool.TrueString; + } + // Create a new request with a Restore target only and specify: // - BuildRequestDataFlags.ClearCachesAfterBuild to ensure the projects will be reloaded from disk for subsequent builds // - BuildRequestDataFlags.SkipNonexistentTargets to ignore missing targets since Restore does not require that all targets exist From b6e5d1d2f4fa981922b2546dd9119202135be836 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 6 Jul 2026 21:24:13 +0000 Subject: [PATCH 3/9] Match NuGet's lowercase "true" for evaluation reuse; add test and perf measurements Co-authored-by: ViktorHofer <7412651+ViktorHofer@users.noreply.github.com> --- src/MSBuild.UnitTests/XMake_Tests.cs | 21 +++++++++++++++++++++ src/MSBuild/XMake.cs | 4 +++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/MSBuild.UnitTests/XMake_Tests.cs b/src/MSBuild.UnitTests/XMake_Tests.cs index d4bce53e21c..b10179d2272 100644 --- a/src/MSBuild.UnitTests/XMake_Tests.cs +++ b/src/MSBuild.UnitTests/XMake_Tests.cs @@ -2615,6 +2615,27 @@ public void RestoreRunsInitialTargets() logContents.ShouldContain("Restore target ran"); } + /// + /// Verifies restore sets the ExcludeRestorePackageImports global property so that NuGet's restore reuses the initial + /// evaluation instead of forcing a second evaluation of every project. + /// + [Fact] + public void RestoreSetsExcludeRestorePackageImports() + { + string projectContents = ObjectModelHelpers.CleanupFileContents( + @" + + + +"); + + string logContents = ExecuteMSBuildExeExpectSuccess(projectContents, arguments: "/t:restore"); + + // The value must be the literal lowercase "true" to exactly match the global property NuGet's restore passes + // (NuGet.targets sets ExcludeRestorePackageImports=true), otherwise evaluation reuse would not occur. + logContents.ShouldContain("ExcludeRestorePackageImports=[true]"); + } + /// /// We check if there is only one target name specified and this logic caused a regression: https://github.com/dotnet/msbuild/issues/3317 /// diff --git a/src/MSBuild/XMake.cs b/src/MSBuild/XMake.cs index c194888fb0d..1c913580e61 100644 --- a/src/MSBuild/XMake.cs +++ b/src/MSBuild/XMake.cs @@ -2067,9 +2067,11 @@ private static BuildResult ExecuteRestore(string projectFile, string toolsVersio // Add the property that NuGet passes when it re-invokes the build during restore. NuGet's restore targets pass // ExcludeRestorePackageImports=true as a global property, which normally forces a second evaluation of every project. // Setting it up front here means the initial evaluation already matches, so it is reused instead of being discarded. + // The value must match NuGet's exactly (the literal lowercase "true" from NuGet.targets) because global property values + // are compared case-sensitively when matching build configurations for evaluation reuse. if (ChangeWaves.AreFeaturesEnabled(ChangeWaves.Wave18_9)) { - restoreGlobalProperties[MSBuildConstants.ExcludeRestorePackageImports] = bool.TrueString; + restoreGlobalProperties[MSBuildConstants.ExcludeRestorePackageImports] = "true"; } // Create a new request with a Restore target only and specify: From 9de7d37799c120324f45b0c84f3fad8cbfbbe754 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 6 Jul 2026 21:26:42 +0000 Subject: [PATCH 4/9] Introduce ExcludeRestorePackageImportsValue constant per code review Co-authored-by: ViktorHofer <7412651+ViktorHofer@users.noreply.github.com> --- src/Framework/MSBuildConstants.cs | 7 +++++++ src/MSBuild.UnitTests/XMake_Tests.cs | 2 +- src/MSBuild/XMake.cs | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Framework/MSBuildConstants.cs b/src/Framework/MSBuildConstants.cs index 51610e9e103..9ab783960d6 100644 --- a/src/Framework/MSBuildConstants.cs +++ b/src/Framework/MSBuildConstants.cs @@ -87,6 +87,13 @@ internal static class MSBuildConstants /// internal const string ExcludeRestorePackageImports = nameof(ExcludeRestorePackageImports); + /// + /// The value MSBuild assigns to during restore. It must match the literal value NuGet passes + /// (lowercase "true" from NuGet.targets) because global property values are compared case-sensitively when matching build configurations + /// for evaluation reuse. + /// + internal const string ExcludeRestorePackageImportsValue = "true"; + /// /// The most current VSGeneralAssemblyVersion known to this version of MSBuild. /// diff --git a/src/MSBuild.UnitTests/XMake_Tests.cs b/src/MSBuild.UnitTests/XMake_Tests.cs index b10179d2272..61ab9a7dc19 100644 --- a/src/MSBuild.UnitTests/XMake_Tests.cs +++ b/src/MSBuild.UnitTests/XMake_Tests.cs @@ -2633,7 +2633,7 @@ public void RestoreSetsExcludeRestorePackageImports() // The value must be the literal lowercase "true" to exactly match the global property NuGet's restore passes // (NuGet.targets sets ExcludeRestorePackageImports=true), otherwise evaluation reuse would not occur. - logContents.ShouldContain("ExcludeRestorePackageImports=[true]"); + logContents.ShouldContain($"ExcludeRestorePackageImports=[{MSBuildConstants.ExcludeRestorePackageImportsValue}]"); } /// diff --git a/src/MSBuild/XMake.cs b/src/MSBuild/XMake.cs index 1c913580e61..837377d3131 100644 --- a/src/MSBuild/XMake.cs +++ b/src/MSBuild/XMake.cs @@ -2071,7 +2071,7 @@ private static BuildResult ExecuteRestore(string projectFile, string toolsVersio // are compared case-sensitively when matching build configurations for evaluation reuse. if (ChangeWaves.AreFeaturesEnabled(ChangeWaves.Wave18_9)) { - restoreGlobalProperties[MSBuildConstants.ExcludeRestorePackageImports] = "true"; + restoreGlobalProperties[MSBuildConstants.ExcludeRestorePackageImports] = MSBuildConstants.ExcludeRestorePackageImportsValue; } // Create a new request with a Restore target only and specify: From ce1d9a2df4446889b10744067b7c64be08ba59d3 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 6 Jul 2026 21:32:29 +0000 Subject: [PATCH 5/9] Add Wave18_10 change wave for MSBuild 18.10 Co-authored-by: ViktorHofer <7412651+ViktorHofer@users.noreply.github.com> --- src/Framework/ChangeWaves.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Framework/ChangeWaves.cs b/src/Framework/ChangeWaves.cs index bd25ffd1b86..808af2d69a6 100644 --- a/src/Framework/ChangeWaves.cs +++ b/src/Framework/ChangeWaves.cs @@ -37,7 +37,8 @@ internal static class ChangeWaves internal static readonly Version Wave18_7 = new Version(18, 7); internal static readonly Version Wave18_8 = new Version(18, 8); internal static readonly Version Wave18_9 = new Version(18, 9); - internal static readonly Version[] AllWaves = [Wave17_10, Wave17_12, Wave17_14, Wave18_3, Wave18_4, Wave18_5, Wave18_6, Wave18_7, Wave18_8, Wave18_9]; + internal static readonly Version Wave18_10 = new Version(18, 10); + internal static readonly Version[] AllWaves = [Wave17_10, Wave17_12, Wave17_14, Wave18_3, Wave18_4, Wave18_5, Wave18_6, Wave18_7, Wave18_8, Wave18_9, Wave18_10]; /// /// Special value indicating that all features behind all Change Waves should be enabled. From 76a9dc563e3869da0fe1d856c22b4d85370b2978 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 6 Jul 2026 21:36:51 +0000 Subject: [PATCH 6/9] Add 18.10 section to ChangeWaves.md Co-authored-by: ViktorHofer <7412651+ViktorHofer@users.noreply.github.com> --- documentation/wiki/ChangeWaves.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/documentation/wiki/ChangeWaves.md b/documentation/wiki/ChangeWaves.md index a305237a731..74e1198e376 100644 --- a/documentation/wiki/ChangeWaves.md +++ b/documentation/wiki/ChangeWaves.md @@ -29,6 +29,8 @@ Change wave checks around features will be removed in the release that accompani ## Current Rotation of Change Waves +### 18.10 + ### 18.9 - [GenerateResource: typed ResX data/metadata entries in Mark-of-the-Web files are now treated as untrusted and blocked with MSB3821; unblock the file (or set MSBUILDDISABLEFEATURESFROMVERSION=18.9) to restore prior behavior. ResXFileRef entries are always blocked regardless of this wave.](https://github.com/dotnet/msbuild/pull/14015) - [TaskHost named-pipe buffers default to 1 MB (was 128 KB), reducing send backpressure for large TaskHostConfiguration packets. Tunable via MSBUILDNODECONNECTIONBUFFERSIZE](https://github.com/dotnet/msbuild/pull/14094) From 6a56c9b6ee0ec3d4ad5b6dadb5147ebd14213d5f Mon Sep 17 00:00:00 2001 From: Viktor Hofer <7412651+ViktorHofer@users.noreply.github.com> Date: Mon, 6 Jul 2026 23:40:01 +0200 Subject: [PATCH 7/9] Remove duplicate entry for ExcludeRestorePackageImports Removed duplicate entry for ExcludeRestorePackageImports in Change Waves documentation. --- documentation/wiki/ChangeWaves.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/documentation/wiki/ChangeWaves.md b/documentation/wiki/ChangeWaves.md index 74e1198e376..02a99bf24b4 100644 --- a/documentation/wiki/ChangeWaves.md +++ b/documentation/wiki/ChangeWaves.md @@ -30,11 +30,11 @@ Change wave checks around features will be removed in the release that accompani ## Current Rotation of Change Waves ### 18.10 +- [Restore passes ExcludeRestorePackageImports=true as a global property so NuGet's restore no longer triggers a second evaluation of every project.](https://github.com/dotnet/msbuild/issues/14273) ### 18.9 - [GenerateResource: typed ResX data/metadata entries in Mark-of-the-Web files are now treated as untrusted and blocked with MSB3821; unblock the file (or set MSBUILDDISABLEFEATURESFROMVERSION=18.9) to restore prior behavior. ResXFileRef entries are always blocked regardless of this wave.](https://github.com/dotnet/msbuild/pull/14015) - [TaskHost named-pipe buffers default to 1 MB (was 128 KB), reducing send backpressure for large TaskHostConfiguration packets. Tunable via MSBUILDNODECONNECTIONBUFFERSIZE](https://github.com/dotnet/msbuild/pull/14094) -- [Restore passes ExcludeRestorePackageImports=true as a global property so NuGet's restore no longer triggers a second evaluation of every project.](https://github.com/dotnet/msbuild/issues/14273) ### 18.8 - [RAR task: across multiple input properties, resolve relative paths against the project directory (not the process current directory)](https://github.com/dotnet/msbuild/pull/13319) From 777da3cd5eb812b4c82e88649af9dfc93dd9dfdd Mon Sep 17 00:00:00 2001 From: Viktor Hofer <7412651+ViktorHofer@users.noreply.github.com> Date: Mon, 6 Jul 2026 23:40:33 +0200 Subject: [PATCH 8/9] Update feature wave check from Wave18_9 to Wave18_10 --- src/MSBuild/XMake.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MSBuild/XMake.cs b/src/MSBuild/XMake.cs index 837377d3131..48d77e940f7 100644 --- a/src/MSBuild/XMake.cs +++ b/src/MSBuild/XMake.cs @@ -2069,7 +2069,7 @@ private static BuildResult ExecuteRestore(string projectFile, string toolsVersio // Setting it up front here means the initial evaluation already matches, so it is reused instead of being discarded. // The value must match NuGet's exactly (the literal lowercase "true" from NuGet.targets) because global property values // are compared case-sensitively when matching build configurations for evaluation reuse. - if (ChangeWaves.AreFeaturesEnabled(ChangeWaves.Wave18_9)) + if (ChangeWaves.AreFeaturesEnabled(ChangeWaves.Wave18_10)) { restoreGlobalProperties[MSBuildConstants.ExcludeRestorePackageImports] = MSBuildConstants.ExcludeRestorePackageImportsValue; } From 3d0edb2ac886ebbd16496865484aef5d976aea50 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 7 Jul 2026 09:49:43 +0000 Subject: [PATCH 9/9] Respect explicit ExcludeRestorePackageImports and test wave-disabled path Co-authored-by: ViktorHofer <7412651+ViktorHofer@users.noreply.github.com> --- src/MSBuild.UnitTests/XMake_Tests.cs | 22 ++++++++++++++++++++++ src/MSBuild/XMake.cs | 5 ++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/MSBuild.UnitTests/XMake_Tests.cs b/src/MSBuild.UnitTests/XMake_Tests.cs index 61ab9a7dc19..7285bd81853 100644 --- a/src/MSBuild.UnitTests/XMake_Tests.cs +++ b/src/MSBuild.UnitTests/XMake_Tests.cs @@ -2636,6 +2636,28 @@ public void RestoreSetsExcludeRestorePackageImports() logContents.ShouldContain($"ExcludeRestorePackageImports=[{MSBuildConstants.ExcludeRestorePackageImportsValue}]"); } + /// + /// Verifies restore does not set the ExcludeRestorePackageImports global property when change wave 18.10 is disabled, + /// preserving the prior behavior for repositories that opt out. + /// + [Fact] + public void RestoreDoesNotSetExcludeRestorePackageImportsWhenWaveDisabled() + { + string projectContents = ObjectModelHelpers.CleanupFileContents( + @" + + + +"); + + Dictionary envVars = new() { { "MSBUILDDISABLEFEATURESFROMVERSION", ChangeWaves.Wave18_10.ToString() } }; + + string logContents = ExecuteMSBuildExeExpectSuccess(projectContents, envsToCreate: envVars, arguments: "/t:restore"); + + // When the wave is disabled, the property must not be injected. + logContents.ShouldContain("ExcludeRestorePackageImports=[]"); + } + /// /// We check if there is only one target name specified and this logic caused a regression: https://github.com/dotnet/msbuild/issues/3317 /// diff --git a/src/MSBuild/XMake.cs b/src/MSBuild/XMake.cs index 48d77e940f7..6111509324c 100644 --- a/src/MSBuild/XMake.cs +++ b/src/MSBuild/XMake.cs @@ -2069,7 +2069,10 @@ private static BuildResult ExecuteRestore(string projectFile, string toolsVersio // Setting it up front here means the initial evaluation already matches, so it is reused instead of being discarded. // The value must match NuGet's exactly (the literal lowercase "true" from NuGet.targets) because global property values // are compared case-sensitively when matching build configurations for evaluation reuse. - if (ChangeWaves.AreFeaturesEnabled(ChangeWaves.Wave18_10)) + // Only set it when the user has not explicitly supplied a value so that an explicit opt-out (e.g. + // /p:ExcludeRestorePackageImports=false) is respected instead of being silently overwritten. + if (ChangeWaves.AreFeaturesEnabled(ChangeWaves.Wave18_10) + && !globalProperties.ContainsKey(MSBuildConstants.ExcludeRestorePackageImports)) { restoreGlobalProperties[MSBuildConstants.ExcludeRestorePackageImports] = MSBuildConstants.ExcludeRestorePackageImportsValue; }