2016-01-04 12:36:46 -08:00
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
2016-10-27 18:46:43 -07:00
using System.Collections.Generic ;
2016-04-19 22:51:32 -05:00
using Microsoft.DotNet.Cli.CommandLine ;
2016-01-04 12:36:46 -08:00
using Microsoft.DotNet.Cli.Utils ;
2016-10-27 18:46:43 -07:00
using Microsoft.DotNet.Tools.MSBuild ;
2016-01-04 12:36:46 -08:00
namespace Microsoft.DotNet.Tools.Restore
{
2016-10-27 18:46:43 -07:00
public class RestoreCommand
2016-01-04 12:36:46 -08:00
{
2016-01-30 21:47:50 -08:00
public static int Run ( string [ ] args )
2016-01-04 12:36:46 -08:00
{
DebugHelper . HandleDebugSwitch ( ref args ) ;
2016-10-27 18:46:43 -07:00
CommandLineApplication cmd = new CommandLineApplication ( throwOnUnexpectedArg : false )
{
Name = "restore" ,
FullName = "restore" ,
Description = "restore for msbuild" ,
AllowArgumentSeparator = true ,
ArgumentSeparatorHelpText = HelpMessageStrings . MSBuildAdditionalArgsHelpText
} ;
cmd . HelpOption ( "-h|--help" ) ;
var argRoot = cmd . Argument (
"[root]" ,
"Optional path to a project file or MSBuild arguments." ,
multipleValues : true ) ;
var sourceOption = cmd . Option (
"-s|--source <source>" ,
"Specifies a NuGet package source to use during the restore." ,
CommandOptionType . MultipleValue ) ;
var packagesOption = cmd . Option (
"--packages <packagesDirectory>" ,
"Directory to install packages in." ,
CommandOptionType . SingleValue ) ;
var disableParallelOption = cmd . Option (
"--disable-parallel" ,
"Disables restoring multiple projects in parallel." ,
CommandOptionType . NoValue ) ;
var configFileOption = cmd . Option (
"--configfile <file>" ,
"The NuGet configuration file to use." ,
CommandOptionType . SingleValue ) ;
var noCacheOption = cmd . Option (
"--no-cache" ,
"Do not cache packages and http requests." ,
CommandOptionType . NoValue ) ;
var ignoreFailedSourcesOption = cmd . Option (
"--ignore-failed-sources" ,
"Treat package source failures as warnings." ,
CommandOptionType . NoValue ) ;
var noDependenciesOption = cmd . Option (
"--no-dependencies" ,
"Set this flag to ignore project to project references and only restore the root project" ,
CommandOptionType . NoValue ) ;
cmd . OnExecute ( ( ) = >
{
var msbuildArgs = new List < string > ( )
{
"/NoLogo" ,
"/t:Restore" ,
"/ConsoleLoggerParameters:Verbosity=Minimal"
} ;
if ( sourceOption . HasValue ( ) )
{
msbuildArgs . Add ( $"/p:RestoreSources={string.Join(" % 3 B ", sourceOption.Values)}" ) ;
}
if ( packagesOption . HasValue ( ) )
{
msbuildArgs . Add ( $"/p:RestorePackagesPath={packagesOption.Value()}" ) ;
}
if ( disableParallelOption . HasValue ( ) )
{
msbuildArgs . Add ( $"/p:RestoreDisableParallel=true" ) ;
}
if ( configFileOption . HasValue ( ) )
{
msbuildArgs . Add ( $"/p:RestoreConfigFile={configFileOption.Value()}" ) ;
}
if ( noCacheOption . HasValue ( ) )
{
msbuildArgs . Add ( $"/p:RestoreNoCache=true" ) ;
}
if ( ignoreFailedSourcesOption . HasValue ( ) )
{
msbuildArgs . Add ( $"/p:RestoreIgnoreFailedSources=true" ) ;
}
if ( noDependenciesOption . HasValue ( ) )
{
msbuildArgs . Add ( $"/p:RestoreRecursive=false" ) ;
}
// Add in arguments
msbuildArgs . AddRange ( argRoot . Values ) ;
// Add remaining arguments that the parser did not understand
msbuildArgs . AddRange ( cmd . RemainingArguments ) ;
return new MSBuildForwardingApp ( msbuildArgs ) . Execute ( ) ;
} ) ;
return cmd . Execute ( args ) ;
2016-01-04 12:36:46 -08:00
}
}
2016-01-12 16:36:31 -08:00
}