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
This commit is contained in:
Justin Emgarten 2016-10-12 23:14:55 -07:00
parent 1926d0e4a4
commit fcdc23233e
2 changed files with 32 additions and 1 deletions

View file

@ -0,0 +1,18 @@
<!--
***********************************************************************************************
Microsoft.NuGet.ImportAfter.targets
WARNING: DO NOT MODIFY this file unless you are knowledgeable about MSBuild and have
created a backup copy. Incorrect changes to this file will make it
impossible to load or build your projects from the command-line or the IDE.
Copyright (c) .NET Foundation. All rights reserved.
***********************************************************************************************
-->
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- Import NuGet.targets for Restore -->
<PropertyGroup>
<NuGetRestoreTargets Condition="'$(NuGetRestoreTargets)'==''">$(MSBuildExtensionsPath)\NuGet.targets</NuGetRestoreTargets>
</PropertyGroup>
<Import Condition="Exists('$(NuGetRestoreTargets)')" Project="$(NuGetRestoreTargets)" />
</Project>

View file

@ -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<string>()
@ -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);