From fcdc23233e388c4a9c1f6c857ecd697b09621c69 Mon Sep 17 00:00:00 2001 From: Justin Emgarten Date: Wed, 12 Oct 2016 23:14:55 -0700 Subject: [PATCH] Recursive restore and solution restore support This change adds support for restoring solution files with msbuild /t:Restore and dotnet restore3. Restoring a project file will now recursively restore all dependency projects to match build. Fixes https://github.com/dotnet/cli/issues/4252 Related to: https://github.com/NuGet/Home/issues/2993 --- .../Microsoft.NuGet.ImportAfter.targets | 18 ++++++++++++++++++ src/dotnet/commands/dotnet-restore3/Program.cs | 15 ++++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 resources/MSBuildImports/15.0/SolutionFile/ImportAfter/Microsoft.NuGet.ImportAfter.targets diff --git a/resources/MSBuildImports/15.0/SolutionFile/ImportAfter/Microsoft.NuGet.ImportAfter.targets b/resources/MSBuildImports/15.0/SolutionFile/ImportAfter/Microsoft.NuGet.ImportAfter.targets new file mode 100644 index 000000000..433922aac --- /dev/null +++ b/resources/MSBuildImports/15.0/SolutionFile/ImportAfter/Microsoft.NuGet.ImportAfter.targets @@ -0,0 +1,18 @@ + + + + + $(MSBuildExtensionsPath)\NuGet.targets + + + diff --git a/src/dotnet/commands/dotnet-restore3/Program.cs b/src/dotnet/commands/dotnet-restore3/Program.cs index 7a8d5f0af..1a753dc7f 100644 --- a/src/dotnet/commands/dotnet-restore3/Program.cs +++ b/src/dotnet/commands/dotnet-restore3/Program.cs @@ -60,6 +60,12 @@ namespace Microsoft.DotNet.Tools.Restore3 "Treat package source failures as warnings.", CommandOptionType.NoValue); + // Use a boolean argument instead of a switch to match nuget.exe + var recursive = cmd.Option( + "--recursive", + "Restore all dependency projects.", + CommandOptionType.BoolValue); + cmd.OnExecute(() => { var msbuildArgs = new List() @@ -69,7 +75,7 @@ namespace Microsoft.DotNet.Tools.Restore3 if (sourceOption.HasValue()) { - msbuildArgs.Add($"/p:RestoreSources={string.Join(";", sourceOption.Values)}"); + msbuildArgs.Add($"/p:RestoreSources={string.Join("%3B", sourceOption.Values)}"); } if (packagesOption.HasValue()) @@ -97,6 +103,13 @@ namespace Microsoft.DotNet.Tools.Restore3 msbuildArgs.Add($"/p:RestoreIgnoreFailedSources=true"); } + // By default restore is recursive, if set to false turn it off. + // If the argument is not present use the default behavior. + if (recursive.BoolValue == false) + { + msbuildArgs.Add($"/p:RestoreRecursive=false"); + } + // Add in arguments msbuildArgs.AddRange(argRoot.Values);