Skip to content

Improve NuGet.targets perf #1866

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 string GetMSBuildArguments(

// 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 string GetMSBuildArguments(
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");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not in love with the fact that this is entirely opt-in. If there's a smart way for us to detect they're using MSBuild 15, I think it should be on by default and be opt-out. What do you think?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have any ideas on how to get that? Since this is only for nuget.exe I was planning to fix that in a later PR. MSBuild and dotnet will use the 15.5 features by default.

Ideally it would determine this in the target, but the only property I could find was for 15.0 and it did not include the minor version.

NuGet could potentially probe the msbuild.exe it finds to read the assembly version, it might be worth the cost of this.

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
Loading