dotnet-installer/src/dotnet/commands/dotnet-build/Program.cs

74 lines
2 KiB
C#
Raw Normal View History

// 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;
using Microsoft.DotNet.Cli.CommandLine;
using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.Tools.MSBuild;
using System.Diagnostics;
using System;
using Microsoft.DotNet.Cli;
2017-03-09 14:30:45 -08:00
using Parser = Microsoft.DotNet.Cli.Parser;
namespace Microsoft.DotNet.Tools.Build
{
2017-02-23 11:24:36 -08:00
public class BuildCommand : MSBuildForwardingApp
{
2017-02-14 11:38:01 -08:00
public BuildCommand(IEnumerable<string> msbuildArgs, string msbuildPath = null)
2017-02-23 11:24:36 -08:00
: base(msbuildArgs, msbuildPath)
{
}
2017-02-14 11:38:01 -08:00
public static BuildCommand FromArgs(string[] args, string msbuildPath = null)
{
2017-03-09 14:30:45 -08:00
DebugHelper.HandleDebugSwitch(ref args);
var msbuildArgs = new List<string>();
var parser = Parser.Instance;
var result = parser.ParseFrom("dotnet build", args);
Reporter.Output.WriteLine(result.Diagram());
result.ShowHelpIfRequested();
var appliedBuildOptions = result["dotnet"]["build"];
if (result.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-03-09 14:30:45 -08:00
msbuildArgs.Add("/t:Build");
}
2017-03-09 14:30:45 -08:00
msbuildArgs.AddRange(appliedBuildOptions.OptionValuesToBeForwarded());
msbuildArgs.AddRange(appliedBuildOptions.Arguments);
2017-03-09 16:39:49 -08:00
msbuildArgs.Add($"/clp:Summary");
2017-02-16 14:18:23 -08:00
return new BuildCommand(msbuildArgs, msbuildPath);
}
public static int Run(string[] args)
{
DebugHelper.HandleDebugSwitch(ref args);
BuildCommand cmd;
try
{
cmd = FromArgs(args);
}
catch (CommandCreationException e)
{
return e.ExitCode;
}
return cmd.Execute();
}
}
}