Summary
Executes a generic tool/process based on arguments, settings and redirects standard output.
Syntax
[CakeMethodAlias]
[CakeAliasCategory("Command")]
public static int Command(this ICakeContext context, CommandSettings settings, out string standardOutput, ProcessArgumentBuilder arguments = null)
Examples
using System.Text.Json.Serialization;
using System.Text.Json;
#tool dotnet:?package=DPI&version=2022.8.21.54
// Reusable tools settings i.e. created in setup.
var settings = new CommandSettings {
ToolName = "DPI",
ToolExecutableNames = new []{ "dpi", "dpi.exe" },
};
// Example with ProcessArgumentBuilder
var exitCode = Command(
settings,
out var standardOutput,
new ProcessArgumentBuilder()
.Append("nuget")
.AppendQuoted(Context.Environment.WorkingDirectory.FullPath)
.AppendSwitch("--output", " ", "JSON")
.Append("analyze")
);
var packageReferences = JsonSerializer.Deserialize<DPIPackageReference[]>(
standardOutput
);
// Example with implicit ProcessArgumentBuilder
var implicitExitCode = Command(
settings,
out var implicitStandardOutput,
$"nuget --output JSON analyze"
);
var implicitPackageReferences = JsonSerializer.Deserialize<DPIPackageReference[]>(
implicitStandardOutput
);
// Record used in example above
public record DPIPackageReference(
[property: JsonPropertyName("source")]
string Source,
[property: JsonPropertyName("sourceType")]
string SourceType,
[property: JsonPropertyName("packageId")]
string PackageId,
[property: JsonPropertyName("version")]
string Version
);
Attributes
Parameters
Return Value
Type |
Description |
int |
The exit code. |