Create a dotnet msbuild command and fill out the applicable command line arguments to dotnet build3.

Fix #4203
This commit is contained in:
Eric Erhardt 2016-09-22 14:47:50 -05:00
parent 3a567e5957
commit d6adea1af0
4 changed files with 89 additions and 8 deletions

View file

@ -5,13 +5,13 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Loader;
using System.Text;
using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.Configurer;
using Microsoft.DotNet.PlatformAbstractions;
using Microsoft.DotNet.ProjectModel.Server;
using Microsoft.DotNet.Tools.Build;
using Microsoft.DotNet.Tools.Build3;
using Microsoft.DotNet.Tools.Compiler;
using Microsoft.DotNet.Tools.Compiler.Csc;
using Microsoft.DotNet.Tools.Help;
@ -44,6 +44,7 @@ namespace Microsoft.DotNet.Cli
["run"] = RunCommand.Run,
["test"] = TestCommand.Run,
["build3"] = Build3Command.Run,
["msbuild"] = MSBuildCommand.Run,
["run3"] = Run3Command.Run,
["restore3"] = Restore3Command.Run,
["vstest"] = VSTestCommand.Run,

View file

@ -1,19 +1,87 @@
// 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;
using Microsoft.DotNet.Cli.CommandLine;
using Microsoft.DotNet.Cli.Utils;
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
namespace Microsoft.DotNet.Cli
namespace Microsoft.DotNet.Tools.Build3
{
public class Build3Command
{
public static int Run(string[] args)
{
return new MSBuildForwardingApp(args).Execute();
DebugHelper.HandleDebugSwitch(ref args);
CommandLineApplication app = new CommandLineApplication(throwOnUnexpectedArg: false);
app.Name = "dotnet build3";
app.FullName = ".NET Builder";
app.Description = "Builder for the .NET Platform. Delegates to the MSBuild 'Build' target in the project file.";
app.AllowArgumentSeparator = true;
app.HelpOption("-h|--help");
CommandArgument projectArgument = app.Argument("<PROJECT>",
"The MSBuild project file to build. If a project file is not specified," +
" MSBuild searches the current working directory for a file that has a file extension that ends in `proj` and uses that file.");
CommandOption outputOption = app.Option("-o|--output <OUTPUT_DIR>", "Directory in which to place outputs", CommandOptionType.SingleValue);
CommandOption frameworkOption = app.Option("-f|--framework <FRAMEWORK>", "Compile a specific framework", CommandOptionType.SingleValue);
CommandOption configurationOption = app.Option("-c|--configuration <CONFIGURATION>", "Configuration under which to build", CommandOptionType.SingleValue);
CommandOption versionSuffixOption = app.Option("--version-suffix <VERSION_SUFFIX>", "Defines the value for the $(VersionSuffix) property in the project", CommandOptionType.SingleValue);
CommandOption noIncrementalOption = app.Option("--no-incremental", "Set this flag to turn off incremental build", CommandOptionType.NoValue);
CommandOption noDependenciesOption = app.Option("--no-dependencies", "Set this flag to ignore project to project references and only build the root project", CommandOptionType.NoValue);
app.OnExecute(() =>
{
List<string> msbuildArgs = new List<string>();
if (!string.IsNullOrEmpty(projectArgument.Value))
{
msbuildArgs.Add(projectArgument.Value);
}
if (noIncrementalOption.HasValue())
{
msbuildArgs.Add("/t:Rebuild");
}
else
{
msbuildArgs.Add("/t:Build");
}
if (outputOption.HasValue())
{
msbuildArgs.Add($"/p:OutputPath={outputOption.Value()}");
}
if (frameworkOption.HasValue())
{
msbuildArgs.Add($"/p:TargetFramework={frameworkOption.Value()}");
}
if (configurationOption.HasValue())
{
msbuildArgs.Add($"/p:Configuration={configurationOption.Value()}");
}
if (versionSuffixOption.HasValue())
{
msbuildArgs.Add($"/p:VersionSuffix={versionSuffixOption.Value()}");
}
if (noDependenciesOption.HasValue())
{
msbuildArgs.Add("/p:BuildProjectReferences=false");
}
msbuildArgs.AddRange(app.RemainingArguments);
return new MSBuildForwardingApp(msbuildArgs).Execute();
});
return app.Execute(args);
}
}
}

View file

@ -2,7 +2,6 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.PlatformAbstractions;
using System;
using System.Collections.Generic;
using System.IO;

View file

@ -0,0 +1,13 @@
// 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.
namespace Microsoft.DotNet.Cli
{
public class MSBuildCommand
{
public static int Run(string[] args)
{
return new MSBuildForwardingApp(args).Execute();
}
}
}