MyTrout.Pipelines.Steps.IO.Command 2.1.0

dotnet add package MyTrout.Pipelines.Steps.IO.Command --version 2.1.0
                    
NuGet\Install-Package MyTrout.Pipelines.Steps.IO.Command -Version 2.1.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="MyTrout.Pipelines.Steps.IO.Command" Version="2.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MyTrout.Pipelines.Steps.IO.Command" Version="2.1.0" />
                    
Directory.Packages.props
<PackageReference Include="MyTrout.Pipelines.Steps.IO.Command" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add MyTrout.Pipelines.Steps.IO.Command --version 2.1.0
                    
#r "nuget: MyTrout.Pipelines.Steps.IO.Command, 2.1.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package MyTrout.Pipelines.Steps.IO.Command@2.1.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=MyTrout.Pipelines.Steps.IO.Command&version=2.1.0
                    
Install as a Cake Addin
#tool nuget:?package=MyTrout.Pipelines.Steps.IO.Command&version=2.1.0
                    
Install as a Cake Tool

MyTrout.Pipelines.Steps.IO.Command

Build Status nuget GitHub stars GitHub forks License: MIT

Quality Gate Status Coverage Maintainability Rating Security Rating Vulnerabilities

Introduction

MyTrout.Pipelines.Steps.IO.Command provides a Pipeline Step to execute a command line utility.

MyTrout.Pipelines.Steps.IO.Command targets .NET 6.0 and .NET 7.0.

For more details on Pipelines, see Pipelines.Core

For more details on Pipelines.Hosting, see Pipelines.Hosting

For a list of available steps, see Available Steps

Installing via NuGet

Install-Package MyTrout.Pipelines.Steps.IO.Command

Software dependencies

1. MyTrout.Pipelines.Steps.IO.Files 4.0.0 minimum.

All software dependencies listed above use the MIT License.

How do I run the Windows Defender Antivirus command and add entries using this library ?


    using MyTrout.Pipelines;
    using MyTrout.Pipelines.Hosting;
    using MyTrout.Pipelines.Steps.IO.Command
    using System;
    using System.Linq;
    using System.Threading.Tasks;

    namespace MyTrout.Pipeline.IO.Command.Samples
    {
        public class Program
        {
            public static async Task Main(string[] args)
            {
                var host = Host.CreateDefaultBuilder(args)
                                    .AddStepDependency<WindowsDefenderAmtivirusOptions>()
                                    .UsePipeline(builder => 
                                    {
                                        builder
                                            .AddStep<GetAFileNameToScanStep>()
                                            .AddStep<ExecuteCommandStep>()
                                    })
                                    .Build();

                //
                // IMPORTANT NOTE FOR DEVELOPERS:
                // 
                // Use StartAsync() to allow the caller to review the PipelineContext after execution.
                //
                await host.StartAsync().ConfigureAwait(false);

                var context = host.Services.GetService<PipelineContext>();

                if(context.Errors.Any())
                {
                    // TODO: Errors have already been logged, do any special error processing here.
                }

                await host.StopAsync().ConfigureAwait(false);

                return 0;
            }
        }
    }
}

How do I run dotnet Console Applications on Windows using ExecuteCommandOptions

This configuration will run a simple Windows Console Application named AppName.exe.

{
    "ExecuteCommandOptions":
    {
        Arguments: "--argument1 value1",
        CommandString: "C:\\Program Files\\AppName\\AppName.exe",
        ExpectedResult: "Hysterical Monkey"
    }
}

This configuration would run: C:\Program Files\AppName\AppName.exe --argument1 value1

If the execution of the command results in an output that contains 'Hysterical Monkey', a "CommandLineStatus" item of "Succeeded" will be placed in PipelineContext. If the execution of the command results in an output does not contain 'Hysterical Monkey', a "CommandLineStatus" item of "Failed" will be placed in PipelineContext.

How do I run dotnet Console Applications on Windows using ExecuteCommandOptions and use the IncludeFileNameTransformInArguments

The step will perform a string replacement using a value that is passed in the PipelineContext via FileConstants.TARGET_FILE. Any number of arguments may be passed in, but must the replacement value "{0}" must be included to perform the transform.

{
    "ExecuteCommandOptions":
    {
        Arguments: "--fileName: /"{0}/"",
        CommandString: "C:\\Program Files\\AppName\\AppName.exe",
        ExpectedResult: "Hysterical Monkey",
        IncludeFileNameTransformInArguments = true
    }
}

Once an entry named "TARGET_FILE" with a value of "D:\Data\1234.txt" is added to PipelineContext.Items, this configuration would run: C:\Program Files\AppName\AppName.exe --fileName "D:\Data\1234.txt"

If the execution of the command results in an output that contains 'Hysterical Monkey', a "CommandLineStatus" item of "Succeeded" will be placed in PipelineContext.Items. If the execution of the command results in an output does not contain 'Hysterical Monkey', a "CommandLineStatus" item of "Failed" will be placed in PipelineContext.Items.

How do I run dotnet Console Applications on Linux using ExecuteCommandOptions

The configuration to run a standard Linux Console application is slightly different compared to the Windows version. First, the Linux Console application compiles to a .dll which must be run using the "dotnet" command.

{
    "ExecuteCommandOptions":
    {
        Arguments: "/home/app/AppName/AppName.dll" --fileName {0}",
        CommandString: "dotnet",
        ExpectedResult: "Hysterical Monkey",
        IncludeFileNameTransformInArguments = true
    }
}

Once an entry named "TARGET_FILE" with a value of "/home/app/AppName/data.txt" is added to PipelineContext.Items, this configuration would run: dotnet /home/app/AppName/AppName.dll --fileName /home/app/AppName/data.txt

Build the software locally.

1. Clone the software from the Pipelines repository.
2. Build the software in Visual Studio 2019 to pull down all of the dependencies from nuget.org.
3. In Visual Studio, run all tests.  All of the should pass.
4. If you have Visual Studio Enterprise 2019, analyze the code coverage; it should be 100%.
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.1.0 394 12/6/2022
2.0.0 461 6/16/2022
1.1.0 370 12/26/2021
1.0.0 425 6/30/2021
0.2.0-beta 319 1/23/2021
0.1.1-beta 337 1/21/2021