reduce some repetition
This commit is contained in:
parent
de7587782e
commit
c75d2e446e
8 changed files with 131 additions and 291 deletions
|
@ -11,13 +11,11 @@ using Microsoft.DotNet.Cli;
|
||||||
|
|
||||||
namespace Microsoft.DotNet.Tools.Build
|
namespace Microsoft.DotNet.Tools.Build
|
||||||
{
|
{
|
||||||
public class BuildCommand
|
public class BuildCommand : MSBuildForwardingApp
|
||||||
{
|
{
|
||||||
private MSBuildForwardingApp _forwardingApp;
|
|
||||||
|
|
||||||
public BuildCommand(IEnumerable<string> msbuildArgs, string msbuildPath = null)
|
public BuildCommand(IEnumerable<string> msbuildArgs, string msbuildPath = null)
|
||||||
|
: base(msbuildArgs, msbuildPath)
|
||||||
{
|
{
|
||||||
_forwardingApp = new MSBuildForwardingApp(msbuildArgs, msbuildPath);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static BuildCommand FromArgs(string[] args, string msbuildPath = null)
|
public static BuildCommand FromArgs(string[] args, string msbuildPath = null)
|
||||||
|
@ -132,15 +130,5 @@ namespace Microsoft.DotNet.Tools.Build
|
||||||
|
|
||||||
return cmd.Execute();
|
return cmd.Execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ProcessStartInfo GetProcessStartInfo()
|
|
||||||
{
|
|
||||||
return _forwardingApp.GetProcessStartInfo();
|
|
||||||
}
|
|
||||||
|
|
||||||
public int Execute()
|
|
||||||
{
|
|
||||||
return GetProcessStartInfo().Execute();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,95 +0,0 @@
|
||||||
// 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;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
|
||||||
using Microsoft.DotNet.Cli.Utils;
|
|
||||||
using Microsoft.DotNet.Tools.MSBuild;
|
|
||||||
using Microsoft.DotNet.Tools.Restore;
|
|
||||||
using Microsoft.DotNet.Cli.CommandLine;
|
|
||||||
|
|
||||||
namespace Microsoft.DotNet.Tools.Cache
|
|
||||||
{
|
|
||||||
public partial class CacheCommand
|
|
||||||
{
|
|
||||||
private string _msbuildPath;
|
|
||||||
|
|
||||||
public string ProjectArgument { get; set; }
|
|
||||||
public string Framework { get; set; }
|
|
||||||
public string Runtime { get; set; }
|
|
||||||
public string OutputPath { get; set; }
|
|
||||||
public string FrameworkVersion { get; set; }
|
|
||||||
public string IntermediateDir { get; set; }
|
|
||||||
public string Verbosity { get; set; }
|
|
||||||
private bool SkipOptimization { get; set; }
|
|
||||||
private bool PreserveIntermediateDir { get; set; }
|
|
||||||
|
|
||||||
public List<string> ExtraMSBuildArguments { get; set; }
|
|
||||||
|
|
||||||
private CacheCommand(string msbuildPath = null)
|
|
||||||
{
|
|
||||||
_msbuildPath = msbuildPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
private MSBuildForwardingApp CreateForwardingApp(string msbuildPath)
|
|
||||||
{
|
|
||||||
var msbuildArgs = new List<string>();
|
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(ProjectArgument))
|
|
||||||
{
|
|
||||||
throw new InvalidOperationException(LocalizableStrings.SpecifyEntries);
|
|
||||||
}
|
|
||||||
|
|
||||||
msbuildArgs.Add("/t:ComposeCache");
|
|
||||||
msbuildArgs.Add(ProjectArgument);
|
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(Framework))
|
|
||||||
{
|
|
||||||
msbuildArgs.Add($"/p:TargetFramework={Framework}");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(Runtime))
|
|
||||||
{
|
|
||||||
msbuildArgs.Add($"/p:RuntimeIdentifier={Runtime}");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(OutputPath))
|
|
||||||
{
|
|
||||||
OutputPath = Path.GetFullPath(OutputPath);
|
|
||||||
msbuildArgs.Add($"/p:ComposeDir={OutputPath}");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(FrameworkVersion))
|
|
||||||
{
|
|
||||||
msbuildArgs.Add($"/p:FX_Version={FrameworkVersion}");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(IntermediateDir))
|
|
||||||
{
|
|
||||||
msbuildArgs.Add($"/p:ComposeWorkingDir={IntermediateDir}");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (SkipOptimization)
|
|
||||||
{
|
|
||||||
msbuildArgs.Add($"/p:SkipOptimization={SkipOptimization}");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (PreserveIntermediateDir)
|
|
||||||
{
|
|
||||||
msbuildArgs.Add($"/p:PreserveComposeWorkingDir={PreserveIntermediateDir}");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(Verbosity))
|
|
||||||
{
|
|
||||||
msbuildArgs.Add($"/verbosity:{Verbosity}");
|
|
||||||
}
|
|
||||||
|
|
||||||
msbuildArgs.AddRange(ExtraMSBuildArguments);
|
|
||||||
|
|
||||||
return new MSBuildForwardingApp(msbuildArgs, msbuildPath);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -7,11 +7,18 @@ using Microsoft.DotNet.Cli.Utils;
|
||||||
using Microsoft.DotNet.Tools.MSBuild;
|
using Microsoft.DotNet.Tools.MSBuild;
|
||||||
using Microsoft.DotNet.Cli;
|
using Microsoft.DotNet.Cli;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
namespace Microsoft.DotNet.Tools.Cache
|
namespace Microsoft.DotNet.Tools.Cache
|
||||||
{
|
{
|
||||||
public partial class CacheCommand
|
public partial class CacheCommand : MSBuildForwardingApp
|
||||||
{
|
{
|
||||||
|
private CacheCommand(IEnumerable<string> msbuildArgs, string msbuildPath = null)
|
||||||
|
: base(msbuildArgs, msbuildPath)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
public static CacheCommand FromArgs(string[] args, string msbuildPath = null)
|
public static CacheCommand FromArgs(string[] args, string msbuildPath = null)
|
||||||
{
|
{
|
||||||
DebugHelper.HandleDebugSwitch(ref args);
|
DebugHelper.HandleDebugSwitch(ref args);
|
||||||
|
@ -58,32 +65,72 @@ namespace Microsoft.DotNet.Tools.Cache
|
||||||
|
|
||||||
CommandOption verbosityOption = MSBuildForwardingApp.AddVerbosityOption(app);
|
CommandOption verbosityOption = MSBuildForwardingApp.AddVerbosityOption(app);
|
||||||
|
|
||||||
var cache = new CacheCommand(msbuildPath);
|
List<string> msbuildArgs = null;
|
||||||
bool commandExecuted = false;
|
|
||||||
app.OnExecute(() =>
|
app.OnExecute(() =>
|
||||||
{
|
{
|
||||||
commandExecuted = true;
|
msbuildArgs = new List<string>();
|
||||||
cache.Framework = frameworkOption.Value();
|
|
||||||
cache.Runtime = runtimeOption.Value();
|
if (string.IsNullOrEmpty(projectArgument.Value()))
|
||||||
cache.OutputPath = outputOption.Value();
|
{
|
||||||
cache.FrameworkVersion = fxOption.Value();
|
throw new InvalidOperationException(LocalizableStrings.SpecifyEntries);
|
||||||
cache.Verbosity = verbosityOption.Value();
|
}
|
||||||
cache.SkipOptimization = skipOptimizationOption.HasValue();
|
|
||||||
cache.IntermediateDir = workingDir.Value();
|
msbuildArgs.Add("/t:ComposeCache");
|
||||||
cache.PreserveIntermediateDir = preserveWorkingDir.HasValue();
|
msbuildArgs.Add(projectArgument.Value());
|
||||||
cache.ExtraMSBuildArguments = app.RemainingArguments;
|
|
||||||
cache.ProjectArgument = projectArgument.Value();
|
if (!string.IsNullOrEmpty(frameworkOption.Value()))
|
||||||
|
{
|
||||||
|
msbuildArgs.Add($"/p:TargetFramework={frameworkOption.Value()}");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(runtimeOption.Value()))
|
||||||
|
{
|
||||||
|
msbuildArgs.Add($"/p:RuntimeIdentifier={runtimeOption.Value()}");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(outputOption.Value()))
|
||||||
|
{
|
||||||
|
var outputPath = Path.GetFullPath(outputOption.Value());
|
||||||
|
msbuildArgs.Add($"/p:ComposeDir={outputPath}");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(fxOption.Value()))
|
||||||
|
{
|
||||||
|
msbuildArgs.Add($"/p:FX_Version={fxOption.Value()}");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(workingDir.Value()))
|
||||||
|
{
|
||||||
|
msbuildArgs.Add($"/p:ComposeWorkingDir={workingDir.Value()}");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (skipOptimizationOption.HasValue())
|
||||||
|
{
|
||||||
|
msbuildArgs.Add($"/p:SkipOptimization={skipOptimizationOption.HasValue()}");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (preserveWorkingDir.HasValue())
|
||||||
|
{
|
||||||
|
msbuildArgs.Add($"/p:PreserveComposeWorkingDir={preserveWorkingDir.HasValue()}");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(verbosityOption.Value()))
|
||||||
|
{
|
||||||
|
msbuildArgs.Add($"/verbosity:{verbosityOption.Value()}");
|
||||||
|
}
|
||||||
|
|
||||||
|
msbuildArgs.AddRange(app.RemainingArguments);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
});
|
});
|
||||||
|
|
||||||
int exitCode = app.Execute(args);
|
int exitCode = app.Execute(args);
|
||||||
if (!commandExecuted)
|
if (msbuildArgs == null)
|
||||||
{
|
{
|
||||||
throw new CommandCreationException(exitCode);
|
throw new CommandCreationException(exitCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
return cache;
|
return new CacheCommand(msbuildArgs, msbuildPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int Run(string[] args)
|
public static int Run(string[] args)
|
||||||
|
@ -102,15 +149,5 @@ namespace Microsoft.DotNet.Tools.Cache
|
||||||
|
|
||||||
return cmd.Execute();
|
return cmd.Execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ProcessStartInfo GetProcessStartInfo()
|
|
||||||
{
|
|
||||||
return CreateForwardingApp(_msbuildPath).GetProcessStartInfo();
|
|
||||||
}
|
|
||||||
|
|
||||||
public int Execute()
|
|
||||||
{
|
|
||||||
return GetProcessStartInfo().Execute();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,13 +10,11 @@ using System.Diagnostics;
|
||||||
|
|
||||||
namespace Microsoft.DotNet.Tools.Clean
|
namespace Microsoft.DotNet.Tools.Clean
|
||||||
{
|
{
|
||||||
public class CleanCommand
|
public class CleanCommand : MSBuildForwardingApp
|
||||||
{
|
{
|
||||||
private MSBuildForwardingApp _forwardingApp;
|
|
||||||
|
|
||||||
public CleanCommand(IEnumerable<string> msbuildArgs, string msbuildPath = null)
|
public CleanCommand(IEnumerable<string> msbuildArgs, string msbuildPath = null)
|
||||||
|
: base(msbuildArgs, msbuildPath)
|
||||||
{
|
{
|
||||||
_forwardingApp = new MSBuildForwardingApp(msbuildArgs, msbuildPath);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static CleanCommand FromArgs(string[] args, string msbuildPath = null)
|
public static CleanCommand FromArgs(string[] args, string msbuildPath = null)
|
||||||
|
@ -49,7 +47,7 @@ namespace Microsoft.DotNet.Tools.Clean
|
||||||
$"-c|--configuration <{LocalizableStrings.CmdConfiguration}>",
|
$"-c|--configuration <{LocalizableStrings.CmdConfiguration}>",
|
||||||
LocalizableStrings.CmdConfigurationDescription,
|
LocalizableStrings.CmdConfigurationDescription,
|
||||||
CommandOptionType.SingleValue);
|
CommandOptionType.SingleValue);
|
||||||
CommandOption verbosityOption = MSBuildForwardingApp.AddVerbosityOption(app);
|
CommandOption verbosityOption = AddVerbosityOption(app);
|
||||||
|
|
||||||
List<string> msbuildArgs = null;
|
List<string> msbuildArgs = null;
|
||||||
app.OnExecute(() =>
|
app.OnExecute(() =>
|
||||||
|
@ -113,15 +111,5 @@ namespace Microsoft.DotNet.Tools.Clean
|
||||||
|
|
||||||
return cmd.Execute();
|
return cmd.Execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ProcessStartInfo GetProcessStartInfo()
|
|
||||||
{
|
|
||||||
return _forwardingApp.GetProcessStartInfo();
|
|
||||||
}
|
|
||||||
|
|
||||||
public int Execute()
|
|
||||||
{
|
|
||||||
return GetProcessStartInfo().Execute();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,13 +10,11 @@ using System.Diagnostics;
|
||||||
|
|
||||||
namespace Microsoft.DotNet.Tools.Pack
|
namespace Microsoft.DotNet.Tools.Pack
|
||||||
{
|
{
|
||||||
public class PackCommand
|
public class PackCommand : MSBuildForwardingApp
|
||||||
{
|
{
|
||||||
private MSBuildForwardingApp _forwardingApp;
|
|
||||||
|
|
||||||
public PackCommand(IEnumerable<string> msbuildArgs, string msbuildPath = null)
|
public PackCommand(IEnumerable<string> msbuildArgs, string msbuildPath = null)
|
||||||
|
: base(msbuildArgs, msbuildPath)
|
||||||
{
|
{
|
||||||
_forwardingApp = new MSBuildForwardingApp(msbuildArgs, msbuildPath);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PackCommand FromArgs(string[] args, string msbuildPath = null)
|
public static PackCommand FromArgs(string[] args, string msbuildPath = null)
|
||||||
|
@ -66,7 +64,7 @@ namespace Microsoft.DotNet.Tools.Pack
|
||||||
$"<{LocalizableStrings.CmdArgumentProject}>",
|
$"<{LocalizableStrings.CmdArgumentProject}>",
|
||||||
LocalizableStrings.CmdArgumentDescription,
|
LocalizableStrings.CmdArgumentDescription,
|
||||||
multipleValues:true);
|
multipleValues:true);
|
||||||
CommandOption verbosityOption = MSBuildForwardingApp.AddVerbosityOption(cmd);
|
CommandOption verbosityOption = AddVerbosityOption(cmd);
|
||||||
|
|
||||||
List<string> msbuildArgs = null;
|
List<string> msbuildArgs = null;
|
||||||
cmd.OnExecute(() =>
|
cmd.OnExecute(() =>
|
||||||
|
@ -147,15 +145,5 @@ namespace Microsoft.DotNet.Tools.Pack
|
||||||
|
|
||||||
return cmd.Execute();
|
return cmd.Execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ProcessStartInfo GetProcessStartInfo()
|
|
||||||
{
|
|
||||||
return _forwardingApp.GetProcessStartInfo();
|
|
||||||
}
|
|
||||||
|
|
||||||
public int Execute()
|
|
||||||
{
|
|
||||||
return GetProcessStartInfo().Execute();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,12 +5,18 @@ using Microsoft.DotNet.Cli;
|
||||||
using Microsoft.DotNet.Cli.CommandLine;
|
using Microsoft.DotNet.Cli.CommandLine;
|
||||||
using Microsoft.DotNet.Cli.Utils;
|
using Microsoft.DotNet.Cli.Utils;
|
||||||
using Microsoft.DotNet.Tools.MSBuild;
|
using Microsoft.DotNet.Tools.MSBuild;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
|
||||||
namespace Microsoft.DotNet.Tools.Publish
|
namespace Microsoft.DotNet.Tools.Publish
|
||||||
{
|
{
|
||||||
public partial class PublishCommand
|
public partial class PublishCommand : MSBuildForwardingApp
|
||||||
{
|
{
|
||||||
|
private PublishCommand(IEnumerable<string> msbuildArgs, string msbuildPath = null)
|
||||||
|
: base(msbuildArgs, msbuildPath)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
public static PublishCommand FromArgs(string[] args, string msbuildPath = null)
|
public static PublishCommand FromArgs(string[] args, string msbuildPath = null)
|
||||||
{
|
{
|
||||||
DebugHelper.HandleDebugSwitch(ref args);
|
DebugHelper.HandleDebugSwitch(ref args);
|
||||||
|
@ -50,33 +56,67 @@ namespace Microsoft.DotNet.Tools.Publish
|
||||||
$"--filter <{LocalizableStrings.FilterProjOption}>", LocalizableStrings.FilterProjOptionDescription,
|
$"--filter <{LocalizableStrings.FilterProjOption}>", LocalizableStrings.FilterProjOptionDescription,
|
||||||
CommandOptionType.SingleValue);
|
CommandOptionType.SingleValue);
|
||||||
|
|
||||||
CommandOption verbosityOption = MSBuildForwardingApp.AddVerbosityOption(app);
|
CommandOption verbosityOption = AddVerbosityOption(app);
|
||||||
|
|
||||||
var publish = new PublishCommand(msbuildPath);
|
List<string> msbuildArgs = null;
|
||||||
bool commandExecuted = false;
|
|
||||||
app.OnExecute(() =>
|
app.OnExecute(() =>
|
||||||
{
|
{
|
||||||
commandExecuted = true;
|
msbuildArgs = new List<string>();
|
||||||
publish.ProjectPath = projectArgument.Value;
|
|
||||||
publish.Framework = frameworkOption.Value();
|
msbuildArgs.Add("/t:Publish");
|
||||||
publish.Runtime = runtimeOption.Value();
|
|
||||||
publish.OutputPath = outputOption.Value();
|
if (!string.IsNullOrEmpty(projectArgument.Value))
|
||||||
publish.Configuration = configurationOption.Value();
|
{
|
||||||
publish.VersionSuffix = versionSuffixOption.Value();
|
msbuildArgs.Add(projectArgument.Value);
|
||||||
publish.FilterProject = filterProjOption.Value();
|
}
|
||||||
publish.Verbosity = verbosityOption.Value();
|
|
||||||
publish.ExtraMSBuildArguments = app.RemainingArguments;
|
if (!string.IsNullOrEmpty(frameworkOption.Value()))
|
||||||
|
{
|
||||||
|
msbuildArgs.Add($"/p:TargetFramework={frameworkOption.Value()}");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(runtimeOption.Value()))
|
||||||
|
{
|
||||||
|
msbuildArgs.Add($"/p:RuntimeIdentifier={runtimeOption.Value()}");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(outputOption.Value()))
|
||||||
|
{
|
||||||
|
msbuildArgs.Add($"/p:PublishDir={outputOption.Value()}");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(configurationOption.Value()))
|
||||||
|
{
|
||||||
|
msbuildArgs.Add($"/p:Configuration={configurationOption.Value()}");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(versionSuffixOption.Value()))
|
||||||
|
{
|
||||||
|
msbuildArgs.Add($"/p:VersionSuffix={versionSuffixOption.Value()}");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(filterProjOption.Value()))
|
||||||
|
{
|
||||||
|
msbuildArgs.Add($"/p:FilterProjFile={filterProjOption.Value()}");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(verbosityOption.Value()))
|
||||||
|
{
|
||||||
|
msbuildArgs.Add($"/verbosity:{verbosityOption.Value()}");
|
||||||
|
}
|
||||||
|
|
||||||
|
msbuildArgs.AddRange(app.RemainingArguments);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
});
|
});
|
||||||
|
|
||||||
int exitCode = app.Execute(args);
|
int exitCode = app.Execute(args);
|
||||||
if (!commandExecuted)
|
if (msbuildArgs == null)
|
||||||
{
|
{
|
||||||
throw new CommandCreationException(exitCode);
|
throw new CommandCreationException(exitCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
return publish;
|
return new PublishCommand(msbuildArgs, msbuildPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int Run(string[] args)
|
public static int Run(string[] args)
|
||||||
|
@ -95,15 +135,5 @@ namespace Microsoft.DotNet.Tools.Publish
|
||||||
|
|
||||||
return cmd.Execute();
|
return cmd.Execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ProcessStartInfo GetProcessStartInfo()
|
|
||||||
{
|
|
||||||
return CreateForwardingApp(_msbuildPath).GetProcessStartInfo();
|
|
||||||
}
|
|
||||||
|
|
||||||
public int Execute()
|
|
||||||
{
|
|
||||||
return GetProcessStartInfo().Execute();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,83 +0,0 @@
|
||||||
// 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.Linq;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using Microsoft.DotNet.Cli.Utils;
|
|
||||||
using Microsoft.DotNet.Tools.MSBuild;
|
|
||||||
using Microsoft.DotNet.Tools.Restore;
|
|
||||||
|
|
||||||
namespace Microsoft.DotNet.Tools.Publish
|
|
||||||
{
|
|
||||||
public partial class PublishCommand
|
|
||||||
{
|
|
||||||
private string _msbuildPath;
|
|
||||||
|
|
||||||
public string ProjectPath { get; set; }
|
|
||||||
public string Framework { get; set; }
|
|
||||||
public string Runtime { get; set; }
|
|
||||||
public string OutputPath { get; set; }
|
|
||||||
public string Configuration { get; set; }
|
|
||||||
public string VersionSuffix { get; set; }
|
|
||||||
public string FilterProject { get; set; }
|
|
||||||
public string Verbosity { get; set; }
|
|
||||||
|
|
||||||
public List<string> ExtraMSBuildArguments { get; set; }
|
|
||||||
|
|
||||||
private PublishCommand(string msbuildPath = null)
|
|
||||||
{
|
|
||||||
_msbuildPath = msbuildPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
private MSBuildForwardingApp CreateForwardingApp(string msbuildPath)
|
|
||||||
{
|
|
||||||
List<string> msbuildArgs = new List<string>();
|
|
||||||
|
|
||||||
msbuildArgs.Add("/t:Publish");
|
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(ProjectPath))
|
|
||||||
{
|
|
||||||
msbuildArgs.Add(ProjectPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(Framework))
|
|
||||||
{
|
|
||||||
msbuildArgs.Add($"/p:TargetFramework={Framework}");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(Runtime))
|
|
||||||
{
|
|
||||||
msbuildArgs.Add($"/p:RuntimeIdentifier={Runtime}");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(OutputPath))
|
|
||||||
{
|
|
||||||
msbuildArgs.Add($"/p:PublishDir={OutputPath}");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(Configuration))
|
|
||||||
{
|
|
||||||
msbuildArgs.Add($"/p:Configuration={Configuration}");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(VersionSuffix))
|
|
||||||
{
|
|
||||||
msbuildArgs.Add($"/p:VersionSuffix={VersionSuffix}");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(FilterProject))
|
|
||||||
{
|
|
||||||
msbuildArgs.Add($"/p:FilterProjFile={FilterProject}");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(Verbosity))
|
|
||||||
{
|
|
||||||
msbuildArgs.Add($"/verbosity:{Verbosity}");
|
|
||||||
}
|
|
||||||
|
|
||||||
msbuildArgs.AddRange(ExtraMSBuildArguments);
|
|
||||||
|
|
||||||
return new MSBuildForwardingApp(msbuildArgs, msbuildPath);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -9,29 +9,16 @@ using System.IO;
|
||||||
|
|
||||||
namespace Microsoft.DotNet.Cli
|
namespace Microsoft.DotNet.Cli
|
||||||
{
|
{
|
||||||
public class VSTestForwardingApp
|
public class VSTestForwardingApp : ForwardingApp
|
||||||
{
|
{
|
||||||
private const string VstestAppName = "vstest.console.dll";
|
private const string VstestAppName = "vstest.console.dll";
|
||||||
private readonly ForwardingApp _forwardingApp;
|
|
||||||
|
|
||||||
public VSTestForwardingApp(IEnumerable<string> argsToForward)
|
public VSTestForwardingApp(IEnumerable<string> argsToForward)
|
||||||
|
: base(GetVSTestExePath(), argsToForward)
|
||||||
{
|
{
|
||||||
_forwardingApp = new ForwardingApp(
|
|
||||||
GetVSTestExePath(),
|
|
||||||
argsToForward);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ProcessStartInfo GetProcessStartInfo()
|
private static string GetVSTestExePath()
|
||||||
{
|
|
||||||
return _forwardingApp.GetProcessStartInfo();
|
|
||||||
}
|
|
||||||
|
|
||||||
public int Execute()
|
|
||||||
{
|
|
||||||
return GetProcessStartInfo().Execute();
|
|
||||||
}
|
|
||||||
|
|
||||||
private string GetVSTestExePath()
|
|
||||||
{
|
{
|
||||||
return Path.Combine(AppContext.BaseDirectory, VstestAppName);
|
return Path.Combine(AppContext.BaseDirectory, VstestAppName);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue