Skip to content

Commit 5911b69

Browse files
committed
Improve NuGet.targets performance
* Add BuildInParallel to MSBuild tasks * Add SkipNonexistentTarget support * Reduce TargetFramework iteration
1 parent cf779e8 commit 5911b69

File tree

2 files changed

+243
-109
lines changed

2 files changed

+243
-109
lines changed

src/NuGet.Clients/NuGet.CommandLine/MsBuildUtility.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ public static string GetMSBuildArguments(
248248

249249
// Override the target under ImportsAfter with the current NuGet.targets version.
250250
AddProperty(args, "NuGetRestoreTargets", entryPointTargetPath);
251+
AddProperty(args, "RestoreUseCustomAfterTargets", bool.TrueString);
251252

252253
// Set path to nuget.exe or the build task
253254
AddProperty(args, "RestoreTaskAssemblyFile", nugetExePath);
@@ -259,6 +260,18 @@ public static string GetMSBuildArguments(
259260
AddPropertyIfHasValue(args, "RestorePackagesPath", packagesDirectory);
260261
AddPropertyIfHasValue(args, "SolutionDir", solutionDirectory);
261262

263+
// Disable parallel and use ContinueOnError since this may run on an older
264+
// version of MSBuild that do not support SkipNonexistentTargets.
265+
// When BuildInParallel is used with ContinueOnError it does not continue in
266+
// some scenarios.
267+
// Allow opt in to msbuild 15.5 behavior with NUGET_RESTORE_MSBUILD_USESKIPNONEXISTENT
268+
var nonExistFlag = Environment.GetEnvironmentVariable("NUGET_RESTORE_MSBUILD_USESKIPNONEXISTENT");
269+
if (!StringComparer.OrdinalIgnoreCase.Equals(nonExistFlag, bool.TrueString))
270+
{
271+
AddProperty(args, "RestoreBuildInParallel", bool.FalseString);
272+
AddProperty(args, "RestoreUseSkipNonexistentTargets", bool.FalseString);
273+
}
274+
262275
// Add additional args to msbuild if needed
263276
var msbuildAdditionalArgs = Environment.GetEnvironmentVariable("NUGET_RESTORE_MSBUILD_ARGS");
264277

0 commit comments

Comments
 (0)