DevOpsTargets 1.2.2

dotnet add package DevOpsTargets --version 1.2.2
NuGet\Install-Package DevOpsTargets -Version 1.2.2
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="DevOpsTargets" Version="1.2.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add DevOpsTargets --version 1.2.2
#r "nuget: DevOpsTargets, 1.2.2"
#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.
// Install DevOpsTargets as a Cake Addin
#addin nuget:?package=DevOpsTargets&version=1.2.2

// Install DevOpsTargets as a Cake Tool
#tool nuget:?package=DevOpsTargets&version=1.2.2

devops-targets

Nuget downloads Nuget Build status spell check coverage License: MIT

This are helper deployment scripts used for building, testing deploying application with .NET script or .NET SDK app.

Use with dotnet script;

#! "net6.0"
#r "nuget:DevOpsTargets"

using System.IO;
using static Bullseye.Targets;
using static DevOps.Targets;

var pathToApp = Path.Combine(GetScriptFolder(), "MyApp");
Target("check-version", "Check .NET CLI version", () => Exec("dotnet --version"));
Target("build", "Build .NET App", DependsOn("check-version"), () => WriteLine("Do some work"));

// Run all Bullseye Targets with the System.CommandLine library.
RunAndExit(Args, loggerPrefix: "My App");

Methods

Write Messages

    using static DevOps.Targets;
    
    // Set default max log level. See [DevOps.Terminal](./README.TERMINAL.md)
    // DevOps.Terminal.Out.MaxLogLevel = LogLevel.Verbose;

    // Write a text to the output
    Write(string message, LogLevel.Message);
    Write(string message, LogLevel.Debug);
    Write(string message); // Default to Message
    
    // Write messages to the output on a new line.
    WriteLine(string message, LogLevel.Error);
    WriteLine(string message);

Execute Commands

All commands are executed in the default system terminal. In cmd.exe for Windows and /bin/sh for Mac and Linux.

    using static DevOps.Targets;

    // Start a new command (don't wait for result). Only first argument is required. See DevOps.Terminal.Commands.Command.CreateAndStart.
    var command = CommandStart("sleep 13", workingDirectory: "/usr", outputLogLevel: LogLevel.Verbose);
    var command = CommandStart("echo Test");
    
    // Start a new command and wait for result. Verify exit code.
    var commandResult = CommandExec("sleep 13", workingDirectory: null, outputLogLevel: LogLevel.Verbose, validExitCode: 0);

    // Exec(...) executes all commands in the same terminal instance. See DevOps.Terminal.Terminals.TerminalSingleton.DefaultTerminal.
    // Example (Windows):
    // 
    // Exec("set TEST=1");
    // Exec("echo %TEST%"); // 1

    // Execute a command in a specific directory. Wait for the result.
    var commandResult = Exec("dir", workingDirectory: "c:\\");

    // Execute a command and output the result as Message. Do not validate exit code.
    var commandResult = Exec("dir", LogLevel.Message, validExitCode: null);
    commandResult.Output; // output
    commandResult.ExitCode; // 0

    // The same as the above. See DevOps.Terminal.Terminals.Terminal.Exec(...);
    Exec(TerminalCommand.CreateParse("dir", logLevel: HostLogLevel.Message), validExitCode: null);

Packages and Installers

    using static DevOps.Targets;

    // Install NodeJs version. Both Windows and Linux.
    NodeJs.Install("14.17.1");

    // Find NodeJs and set NODE_PATH if not set.
    NodeJs.SetNodePath();

    // Install Java jdk, If not installed.
    Java.Install("openjdk@1.15.0");

    // Install NPM package, globally.
    Npm.InstallGlobal("@angular/cli");

    // Run 'npm install' in the provided folder.
    Npm.Install("c:\\my-project");

    // Run 'npm ci' in the folder. Provide cache folder path if needed.
    Npm.Ci("c:\\my-project", cacheFolder: null);

    // Run a npm command.
    Npm.Run("test", pathToFolder: "c:\\my=project");

Files and Directories

    using static DevOps.Targets;

    // Gets the calling assembly or c# script folder path.
    var currentPath = GetScriptFolder();

    // Gets the user home directory.
    var home = GetHomeFolder();

    // Ensure the directory exists.
    EnsureDirectoryExists("c:\\Temp");

    // Deletes all provided files and folders as params.
    DeleteAllFilesAndFolders("c:\\Temp", "d:\\image.png" /*, ...*/);

    // Deletes and re-create the folder.
    CleanDirectory("c:\\publish");

    // Get a temp system filename. Example: "c:\Users\my-user\AppData\Local\Temp\72f69d35e54b40e29d9849b71e43a7dc.png".
    var tempFileName = GetTempFileName(".png");

    // Create multi-line content from lines as arguments.
    var content = GetContentFromLines("Line 1", "Line 2");

Download

    using static DevOps.Packages;

    Downloader.DownloadFile("nuget", "6.0.0", "nuget.exe", "https://dist.nuget.org/win-x86-commandline/v6.0.0/nuget.exe");

    Downloader.DownloadAndExtractZipFile("my-tool", "1.0.0", "my-tool.zip", "https://dummy-domain.test/my-tool/zip");

.NET and Transforms

    using static DevOps.Targets;

    // Merge transform .json into another .json
    Transform.TransformSettingsJson(pathToSettingsJson, pathToTransformJson);

    // Find value of a property in json.
    string value = Transform.FindPropertyValueInJson(pathToJson, propertyName);

    // Find value in XML by xpath
    string value = Transform.GetXmlXPathValue(pathToXml, xpath);

    // Replace ${value} in a text file
    Transform.ReplaceInFile(pathToFile, pathToNewFile, params EnvValue[] values);

    // Install .NET SDK when missing
    DotNet.Sdk.Install("5.0");

    // Install .NET tool. Global by default.
    DotNet.Tool.Install("ef");
    DotNet.Tool.Install("dotnetsay", version: "1.0.0", global: false);

    // Uninstall .NET tool. Global by default.
    DotNet.Tool.Uninstall("ef");
    DotNet.Tool.Uninstall("dotnetsay", global: false);

    // Get dotnet tool path. Example %USERPROFILE%\.dotnet\tools\.store\ef for Windows.
    DotNet.Tool.GetGlobalToolStorePath("ef");

    // Build csproj file
    DotNet.Build(pathToCsProj, configuration: "Debug");

    // Publish csproj file
    DotNet.Publish(pathToCsProj, pathToOutput, configuration: "Release");

    // Test csproj file
    DotNet.Test(string pathToCsProj, configuration: "Debug", pathToTrxOutput: null);

    // Test with coverage csproj file
    DotNet.TestWithCoverage(pathToCsProject, pathToTestResults, configuration: "Debug", formats: TestCoverageFormat.Cobertura, DotNetLoggers.JUnit);

SonarScanner

    using static DevOps.Targets;

    // Transform global SonarQube settings with replace variables. The first sdk in the list is the primary one, others a backups.
    Sonarqube.TransformGlobalSettings("c:\\Project\\SonarQube.MySettings.xml", sdks: new [] { "net6.0", "net5.0" }, new EnvValue("BASE_PATH", "c:\\Project"));

    // Run sonar scanner. See the extended example.
    Sonarqube.RunScanner(() => DotNet.Build(solutionDir), solutionDir, organization: "Org", key: "my-key", version: "1.0.0", branch: "main");

Also see samples/.

Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  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 was computed.  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. 
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
1.2.2 10,413 11/17/2021
1.2.1 872 11/16/2021
1.2.0 248 11/15/2021
1.1.1 971 9/16/2021
1.1.0 213 9/16/2021
1.0.0 472 8/2/2021
0.3.0 182 7/7/2021
0.2.0 184 7/7/2021
0.1.0 227 7/6/2021