2015-12-10 13:06:33 -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.
|
|
|
|
|
|
|
|
|
|
using System.Collections.Generic;
|
2017-06-01 21:25:06 -07:00
|
|
|
|
using System.Linq;
|
2016-10-27 18:46:43 -07:00
|
|
|
|
using Microsoft.DotNet.Cli.CommandLine;
|
2016-05-02 11:32:24 -07:00
|
|
|
|
using Microsoft.DotNet.Cli.Utils;
|
2016-10-27 18:46:43 -07:00
|
|
|
|
using Microsoft.DotNet.Tools.MSBuild;
|
2017-06-01 21:25:06 -07:00
|
|
|
|
using Microsoft.DotNet.Tools;
|
2017-02-14 10:41:58 -08:00
|
|
|
|
using Microsoft.DotNet.Cli;
|
2017-06-01 21:25:06 -07:00
|
|
|
|
using Microsoft.DotNet.Tools.Restore;
|
2017-03-09 14:30:45 -08:00
|
|
|
|
using Parser = Microsoft.DotNet.Cli.Parser;
|
2015-12-10 13:06:33 -08:00
|
|
|
|
|
|
|
|
|
namespace Microsoft.DotNet.Tools.Build
|
|
|
|
|
{
|
2017-06-01 21:25:06 -07:00
|
|
|
|
public class BuildCommand : RestoringCommand
|
2015-12-10 13:06:33 -08:00
|
|
|
|
{
|
2017-06-13 00:04:25 -07:00
|
|
|
|
public BuildCommand(
|
|
|
|
|
IEnumerable<string> msbuildArgs,
|
|
|
|
|
IEnumerable<string> userDefinedArguments,
|
|
|
|
|
IEnumerable<string> trailingArguments,
|
|
|
|
|
bool noRestore,
|
|
|
|
|
string msbuildPath = null)
|
|
|
|
|
: base(msbuildArgs, userDefinedArguments, trailingArguments, noRestore, msbuildPath)
|
2015-12-10 13:06:33 -08:00
|
|
|
|
{
|
2017-02-14 10:41:58 -08:00
|
|
|
|
}
|
|
|
|
|
|
2017-02-14 11:38:01 -08:00
|
|
|
|
public static BuildCommand FromArgs(string[] args, string msbuildPath = null)
|
2017-02-14 10:41:58 -08:00
|
|
|
|
{
|
2017-03-09 14:30:45 -08:00
|
|
|
|
var msbuildArgs = new List<string>();
|
|
|
|
|
|
|
|
|
|
var parser = Parser.Instance;
|
|
|
|
|
|
|
|
|
|
var result = parser.ParseFrom("dotnet build", args);
|
|
|
|
|
|
2017-03-13 13:29:03 -07:00
|
|
|
|
result.ShowHelpOrErrorIfAppropriate();
|
2017-03-09 14:30:45 -08:00
|
|
|
|
|
|
|
|
|
var appliedBuildOptions = result["dotnet"]["build"];
|
|
|
|
|
|
2017-10-25 10:42:08 -07:00
|
|
|
|
msbuildArgs.Add($"/clp:Summary");
|
|
|
|
|
|
2017-03-09 17:52:17 -08:00
|
|
|
|
if (appliedBuildOptions.HasOption("--no-incremental"))
|
2016-04-27 16:04:26 -07:00
|
|
|
|
{
|
2017-03-09 14:30:45 -08:00
|
|
|
|
msbuildArgs.Add("/t:Rebuild");
|
|
|
|
|
}
|
|
|
|
|
else
|
2017-02-14 10:41:58 -08:00
|
|
|
|
{
|
2017-03-09 14:30:45 -08:00
|
|
|
|
msbuildArgs.Add("/t:Build");
|
2017-02-14 10:41:58 -08:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-09 14:30:45 -08:00
|
|
|
|
msbuildArgs.AddRange(appliedBuildOptions.OptionValuesToBeForwarded());
|
|
|
|
|
|
|
|
|
|
msbuildArgs.AddRange(appliedBuildOptions.Arguments);
|
|
|
|
|
|
2017-06-01 21:25:06 -07:00
|
|
|
|
bool noRestore = appliedBuildOptions.HasOption("--no-restore");
|
|
|
|
|
|
2017-06-13 00:04:25 -07:00
|
|
|
|
return new BuildCommand(
|
|
|
|
|
msbuildArgs,
|
|
|
|
|
appliedBuildOptions.OptionValuesToBeForwarded(),
|
|
|
|
|
appliedBuildOptions.Arguments,
|
|
|
|
|
noRestore,
|
|
|
|
|
msbuildPath);
|
2017-02-14 10:41:58 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static int Run(string[] args)
|
|
|
|
|
{
|
|
|
|
|
DebugHelper.HandleDebugSwitch(ref args);
|
|
|
|
|
|
|
|
|
|
BuildCommand cmd;
|
2017-03-10 09:08:01 -08:00
|
|
|
|
|
2017-02-14 10:41:58 -08:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
cmd = FromArgs(args);
|
|
|
|
|
}
|
2017-02-15 10:38:41 -08:00
|
|
|
|
catch (CommandCreationException e)
|
2017-02-14 10:41:58 -08:00
|
|
|
|
{
|
|
|
|
|
return e.ExitCode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return cmd.Execute();
|
|
|
|
|
}
|
2015-12-10 13:06:33 -08:00
|
|
|
|
}
|
|
|
|
|
}
|