
This commit implements a `mode` option that can control how an application is published with the `dotnet publish` command. There are three supported modes: * self-contained: publishes a self-contained application (same as --self-contained). * fx-dependent: publishes a framework-dependent application (with an application host when a runtime is specified). * fx-dependent-no-exe: publishes a framework-dependent application without an application host. The default when publishing without a runtime specified is `fx-dependent-no-exe`. The default when publishing with a runtime specified is `self-contained`. `fx-dependent` requires netcoreapp2.1 or later when a runtime is specified. The `--self-contained` option is still supported, but is now hidden so that users will be encouraged to move to the `--mode` option. Fixes #6237.
85 lines
2.5 KiB
C#
85 lines
2.5 KiB
C#
// 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 Microsoft.DotNet.Cli.Utils;
|
|
using NuGet.Frameworks;
|
|
using System.Collections.Generic;
|
|
|
|
namespace Microsoft.DotNet.Tools.Test.Utilities
|
|
{
|
|
public sealed class PublishCommand : DotnetCommand
|
|
{
|
|
private string _framework;
|
|
private string _output;
|
|
private string _runtime;
|
|
private List<string> _targetManifests = new List<string>();
|
|
private string _mode;
|
|
|
|
public PublishCommand WithFramework(string framework)
|
|
{
|
|
_framework = framework;
|
|
return this;
|
|
}
|
|
|
|
public PublishCommand WithFramework(NuGetFramework framework)
|
|
{
|
|
return WithFramework(framework.GetShortFolderName());
|
|
}
|
|
|
|
public PublishCommand WithOutput(string output)
|
|
{
|
|
_output = output;
|
|
return this;
|
|
}
|
|
|
|
public PublishCommand WithRuntime(string runtime)
|
|
{
|
|
_runtime = runtime;
|
|
return this;
|
|
}
|
|
|
|
public PublishCommand WithTargetManifest(string manifest)
|
|
{
|
|
_targetManifests.Add( $"--manifest {manifest}");
|
|
return this;
|
|
}
|
|
|
|
public PublishCommand WithMode(string value)
|
|
{
|
|
_mode = value;
|
|
return this;
|
|
}
|
|
|
|
public override CommandResult Execute(string args = "")
|
|
{
|
|
args = $"publish {BuildArgs()} {args}";
|
|
return base.Execute(args);
|
|
}
|
|
|
|
public override CommandResult ExecuteWithCapturedOutput(string args = "")
|
|
{
|
|
args = $"publish {BuildArgs()} {args}";
|
|
return base.ExecuteWithCapturedOutput(args);
|
|
}
|
|
|
|
private string BuildArgs()
|
|
{
|
|
return string.Join(" ",
|
|
FrameworkOption,
|
|
OutputOption,
|
|
TargetOption,
|
|
RuntimeOption,
|
|
ModeOption);
|
|
}
|
|
|
|
private string FrameworkOption => string.IsNullOrEmpty(_framework) ? "" : $"-f {_framework}";
|
|
|
|
private string OutputOption => string.IsNullOrEmpty(_output) ? "" : $"-o {_output}";
|
|
|
|
private string RuntimeOption => string.IsNullOrEmpty(_runtime) ? "" : $"-r {_runtime}";
|
|
|
|
private string TargetOption => string.Join(" ", _targetManifests);
|
|
|
|
private string ModeOption => string.IsNullOrEmpty(_mode) ? "" : $"--mode {_mode}";
|
|
}
|
|
}
|