Skip to content

Commit

Permalink
Improve NuGet.targets performance (#1866)
Browse files Browse the repository at this point in the history
* Add BuildInParallel to MSBuild tasks
* Add SkipNonexistentTarget support
* Reduce TargetFramework iteration

Fixes NuGet/Home#6310
Fixes NuGet/Home#6311
Fixes NuGet/Home#6312
Fixes NuGet/Home#6061
  • Loading branch information
emgarten committed Dec 14, 2017
1 parent c671316 commit c76d1c2
Show file tree
Hide file tree
Showing 2 changed files with 243 additions and 109 deletions.
13 changes: 13 additions & 0 deletions src/NuGet.Clients/NuGet.CommandLine/MsBuildUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ public static bool IsMsBuildBasedProject(string projectFullPath)

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

// Set path to nuget.exe or the build task
AddProperty(args, "RestoreTaskAssemblyFile", nugetExePath);
Expand All @@ -259,6 +260,18 @@ public static bool IsMsBuildBasedProject(string projectFullPath)
AddPropertyIfHasValue(args, "RestorePackagesPath", packagesDirectory);
AddPropertyIfHasValue(args, "SolutionDir", solutionDirectory);

// Disable parallel and use ContinueOnError since this may run on an older
// version of MSBuild that do not support SkipNonexistentTargets.
// When BuildInParallel is used with ContinueOnError it does not continue in
// some scenarios.
// Allow opt in to msbuild 15.5 behavior with NUGET_RESTORE_MSBUILD_USESKIPNONEXISTENT
var nonExistFlag = Environment.GetEnvironmentVariable("NUGET_RESTORE_MSBUILD_USESKIPNONEXISTENT");
if (!StringComparer.OrdinalIgnoreCase.Equals(nonExistFlag, bool.TrueString))
{
AddProperty(args, "RestoreBuildInParallel", bool.FalseString);
AddProperty(args, "RestoreUseSkipNonexistentTargets", bool.FalseString);
}

// Add additional args to msbuild if needed
var msbuildAdditionalArgs = Environment.GetEnvironmentVariable("NUGET_RESTORE_MSBUILD_ARGS");

Expand Down

0 comments on commit c76d1c2

Please sign in to comment.