2015-12-15 01:39:29 +00: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-04-28 23:30:32 +00:00
|
|
|
|
using Microsoft.DotNet.Cli.Utils;
|
2016-10-28 01:46:43 +00:00
|
|
|
|
using NuGet.Frameworks;
|
2017-03-07 06:57:40 +00:00
|
|
|
|
using System.Collections.Generic;
|
2015-12-15 01:39:29 +00:00
|
|
|
|
|
2015-12-31 01:02:59 +00:00
|
|
|
|
namespace Microsoft.DotNet.Tools.Test.Utilities
|
2015-12-15 01:39:29 +00:00
|
|
|
|
{
|
2017-03-14 21:07:51 +00:00
|
|
|
|
public sealed class PublishCommand : DotnetCommand
|
2015-12-15 01:39:29 +00:00
|
|
|
|
{
|
2016-10-28 01:46:43 +00:00
|
|
|
|
private string _framework;
|
|
|
|
|
private string _output;
|
|
|
|
|
private string _runtime;
|
2017-03-07 06:57:40 +00:00
|
|
|
|
private List<string> _profileFilterProject = new List<string>();
|
2017-04-03 23:09:50 +00:00
|
|
|
|
private bool? _selfContained;
|
|
|
|
|
|
2016-10-28 01:46:43 +00:00
|
|
|
|
public PublishCommand WithFramework(string framework)
|
2016-01-11 21:40:47 +00:00
|
|
|
|
{
|
2016-10-28 01:46:43 +00:00
|
|
|
|
_framework = framework;
|
|
|
|
|
return this;
|
2016-01-11 21:40:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-28 01:46:43 +00:00
|
|
|
|
public PublishCommand WithFramework(NuGetFramework framework)
|
2015-12-15 01:39:29 +00:00
|
|
|
|
{
|
2016-10-28 01:46:43 +00:00
|
|
|
|
return WithFramework(framework.GetShortFolderName());
|
2015-12-15 01:39:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-28 01:46:43 +00:00
|
|
|
|
public PublishCommand WithOutput(string output)
|
2015-12-15 01:39:29 +00:00
|
|
|
|
{
|
2016-10-28 01:46:43 +00:00
|
|
|
|
_output = output;
|
|
|
|
|
return this;
|
2015-12-15 01:39:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-28 01:46:43 +00:00
|
|
|
|
public PublishCommand WithRuntime(string runtime)
|
2016-03-15 18:50:14 +00:00
|
|
|
|
{
|
2016-10-28 01:46:43 +00:00
|
|
|
|
_runtime = runtime;
|
|
|
|
|
return this;
|
2016-03-15 18:50:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-04-03 23:09:50 +00:00
|
|
|
|
public PublishCommand WithProfileProject(string profileproj)
|
2017-02-14 01:56:25 +00:00
|
|
|
|
{
|
2017-03-07 06:57:40 +00:00
|
|
|
|
_profileFilterProject.Add( $" --filter {profileproj}");
|
2017-02-14 01:56:25 +00:00
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-03 23:09:50 +00:00
|
|
|
|
public PublishCommand WithSelfContained(bool value)
|
|
|
|
|
{
|
|
|
|
|
_selfContained = value;
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-28 01:46:43 +00:00
|
|
|
|
public override CommandResult Execute(string args = "")
|
2015-12-15 01:39:29 +00:00
|
|
|
|
{
|
2016-10-28 01:46:43 +00:00
|
|
|
|
args = $"publish {BuildArgs()} {args}";
|
|
|
|
|
return base.Execute(args);
|
2016-03-17 20:46:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-28 01:46:43 +00:00
|
|
|
|
public override CommandResult ExecuteWithCapturedOutput(string args = "")
|
2016-03-17 20:46:46 +00:00
|
|
|
|
{
|
2016-10-28 01:46:43 +00:00
|
|
|
|
args = $"publish {BuildArgs()} {args}";
|
|
|
|
|
return base.ExecuteWithCapturedOutput(args);
|
2015-12-15 01:39:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string BuildArgs()
|
|
|
|
|
{
|
2016-10-28 01:46:43 +00:00
|
|
|
|
return string.Join(" ",
|
|
|
|
|
FrameworkOption,
|
|
|
|
|
OutputOption,
|
2017-02-14 01:56:25 +00:00
|
|
|
|
ProfileProjOption,
|
2017-04-03 23:09:50 +00:00
|
|
|
|
RuntimeOption,
|
|
|
|
|
SelfContainedOption);
|
2015-12-15 01:39:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-03-09 19:36:16 +00:00
|
|
|
|
private string FrameworkOption => string.IsNullOrEmpty(_framework) ? "" : $"-f {_framework}";
|
2016-10-28 01:46:43 +00:00
|
|
|
|
|
|
|
|
|
private string OutputOption => string.IsNullOrEmpty(_output) ? "" : $"-o {_output}";
|
|
|
|
|
|
2016-03-09 19:36:16 +00:00
|
|
|
|
private string RuntimeOption => string.IsNullOrEmpty(_runtime) ? "" : $"-r {_runtime}";
|
2017-02-14 01:56:25 +00:00
|
|
|
|
|
2017-03-07 06:57:40 +00:00
|
|
|
|
private string ProfileProjOption => string.Join(" ", _profileFilterProject);
|
2017-04-03 23:09:50 +00:00
|
|
|
|
|
|
|
|
|
private string SelfContainedOption => _selfContained.HasValue ? $"--self-contained:{_selfContained.Value}" : "";
|
2015-12-15 01:39:29 +00:00
|
|
|
|
}
|
|
|
|
|
}
|