DevOpsTargets 1.2.1
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package DevOpsTargets --version 1.2.1
NuGet\Install-Package DevOpsTargets -Version 1.2.1
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.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add DevOpsTargets --version 1.2.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: DevOpsTargets, 1.2.1"
#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.1 // Install DevOpsTargets as a Cake Tool #tool nuget:?package=DevOpsTargets&version=1.2.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
devops-targets
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 DevOpsTargets.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 DevOpsTargets.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 DevOpsTargets.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 DevOpsTargets.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 DevOpsTargets.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");
.NET and Transforms
using static DevOpsTargets.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);
// 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 DevOpsTargets.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 | Versions 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.
-
net5.0
- Bullseye (>= 3.8.0)
- DevOpsTargets.Terminal (>= 1.2.0)
- System.CommandLine (>= 2.0.0-beta1.21308.1)
-
net6.0
- Bullseye (>= 3.8.0)
- DevOpsTargets.Terminal (>= 1.2.0)
- System.CommandLine (>= 2.0.0-beta1.21308.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.