{"id":24124665,"url":"https://github.com/devteam/csharp-interactive","last_synced_at":"2025-03-27T01:10:53.014Z","repository":{"id":260113277,"uuid":"830383195","full_name":"DevTeam/csharp-interactive","owner":"DevTeam","description":" Build automation system for .NET","archived":false,"fork":false,"pushed_at":"2025-02-27T12:51:28.000Z","size":9533,"stargazers_count":20,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-16T01:32:39.834Z","etag":null,"topics":["build-automation","build-system","build-tool","ci-cd","csharp","csharp-script","dotnet","repl","script","tinuous-integration"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DevTeam.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-07-18T07:04:04.000Z","updated_at":"2025-02-27T12:51:34.000Z","dependencies_parsed_at":"2024-12-17T16:19:37.431Z","dependency_job_id":"e5918e25-8552-4d50-a3d3-6a1b3d03695e","html_url":"https://github.com/DevTeam/csharp-interactive","commit_stats":{"total_commits":304,"total_committers":6,"mean_commits":"50.666666666666664","dds":"0.052631578947368474","last_synced_commit":"ebdd0ae45a393be52e446cddfcd4c92d6098f01a"},"previous_names":["devteam/csharp-interactive"],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DevTeam%2Fcsharp-interactive","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DevTeam%2Fcsharp-interactive/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DevTeam%2Fcsharp-interactive/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DevTeam%2Fcsharp-interactive/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DevTeam","download_url":"https://codeload.github.com/DevTeam/csharp-interactive/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245761295,"owners_count":20667895,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["build-automation","build-system","build-tool","ci-cd","csharp","csharp-script","dotnet","repl","script","tinuous-integration"],"created_at":"2025-01-11T14:35:02.421Z","updated_at":"2025-03-27T01:10:53.006Z","avatar_url":"https://github.com/DevTeam.png","language":"C#","readme":"#  Build automation system for .NET\n\n[![NuGet csi](https://img.shields.io/nuget/v/dotnet-csi?includePreReleases=true)](https://www.nuget.org/packages/dotnet-csi)\n![GitHub](https://img.shields.io/github/license/devteam/csharp-interactive)\n[\u003cimg src=\"http://teamcity.jetbrains.com/app/rest/builds/buildType:(id:OpenSourceProjects_DevTeam_CScriptInteractive_BuildAndTest)/statusIcon.svg\"/\u003e](http://teamcity.jetbrains.com/viewType.html?buildTypeId=OpenSourceProjects_DevTeam_CScriptInteractive_BuildAndTest\u0026guest=1)\n![GitHub Build](https://github.com/DevTeam/csharp-interactive/actions/workflows/main.yml/badge.svg)\n\n![](docs/CSharpInteractive.gif)\n\nC# interactive build automation system makes it easy to build .NET projects. It can be part of your solution as a regular .NET console project or run C# scripts without compiling them, or even run in REPL mode - allowing you to run C# interactively.\n\n![](docs/icon.png)\n\n## Key Features\n\n### ✔️ Three Integrated [Execution Modes](#operating-modes)\nFlexible interoperability between modes for diverse workflow requirements.\n### ✔️ Native Cross-Platform Support\nSeamless operation across Windows, Linux, and macOS environments.\n### ✔️ Debugging Support\nAbility to debug in “.NET build project” mode, allowing developers to efficiently identify and fix problems during the compilation and build process.\n### ✔️ Zero Abstraction Constraints\nNo restrictive abstractions (e.g., Tasks, Targets, DependsOn) to limit script design:\n- Pure .NET codebase – no proprietary syntax or hidden layers\n- Adheres to industry-standard coding practices for maintainability\n### ✔️ Powerful API for building .NET projects\nGranular control over builds, tests, and deployments with streamlined project configuration.\n### ✔️ Summarised statistics\nConsolidated build statistics.\n\n## Operating modes\n\n\u003cdetails\u003e\n\n\u003csummary\u003eInteractive\u003c/summary\u003e\n\nREPL (Read-Eval-Print-Loop) interface for interactive code evaluation. Please see [this page](https://www.nuget.org/packages/dotnet-csi) for installation details.\n\nLaunch the tool in the interactive mode:\n\n```Shell\ndotnet csi\n```\n\nSimply enter C# commands sequentially one line after another and get the result in console output.\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003eRunning C# script\u003c/summary\u003e\n\nDirect execution of C# scripts without prior compilation:\n- Zero-Compilation Workflow - execute .csx files directly using Roslyn scripting engines, bypassing traditional dotnet build steps for rapid iteration.\n- Cross-Platform Scripting\n  - Windows - integrate with PowerShell/PowerShell Core automation pipelines\n  - Linux/macOS - combine with bash/zsh scripts via shebang directives (#!/usr/bin/env dotnet-script)\n  - Dependency Management - resolve NuGet packages in scripts via #r \"nuget: PackageName/Version\" syntax, with local cache optimization.\n\nRun a specified script with a given argument:\n\n```Shell\ndotnet csi ./MyDirectory/hello.csx World \n```\n\nRun a single script located in the _MyDirectory_ directory:\n\n```Shell\ndotnet csi ./MyDirectory World\n```\n\n\u003cdetails\u003e\n\u003csummary\u003eUsage details\u003c/summary\u003e\n\n```Shell\ndotnet csi [options] [--] [script] [script arguments]\n```\n\nExecutes a script if specified, otherwise launches an interactive REPL (Read Eval Print Loop).\n\n`--` - Indicates that the remaining arguments should not be treated as options.\n\n`script` - The path to the script file to run. If no such file is found, the command will treat it as a directory and look for a single script file inside that directory.\n\n`script arguments` - Script arguments are accessible in a script via the global list `Args[index]` by an argument index.\n\n`@file` - Read the response file for more options.\n\nSupported options:\n\n| Option                  | Description                                                                                                                                                     | Alternative form                                                                              |\n|:------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------|\n| --help                  | Show how to use the command.                                                                                                                                    | `/?`, `-h`, `/h`, `/help`                                                                     |\n| --version               | Display the tool version.                                                                                                                                       | `/version`                                                                                    |\n| --source                | Specify the NuGet package source to use. Supported formats: URL, or a UNC directory path.                                                                       | `-s`, `/s`, `/source`                                                                         |\n| --property \u003ckey=value\u003e  | Define a key-value pair(s) for the script properties called _Props_, which is accessible in scripts.                                                            | `-p`, `/property`, `/p`                                                                       |\n| --property:\u003ckey=value\u003e  | Define a key-value pair(s) in MSBuild style for the script properties called _Props_, which is accessible in scripts.                                           | `-p:\u003ckey=value\u003e`, `/property:\u003ckey=value\u003e`, `/p:\u003ckey=value\u003e`, `--property:key1=val1;key2=val2` |\n\n\u003c/details\u003e\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003e.NET build project\u003c/summary\u003e\n\nSeamless integration into existing solutions as a standard .NET console project. Please see [this page](https://github.com/DevTeam/csharp-interactive/wiki/Install-the-C%23-script-template) for details on how to install the [project template](https://www.nuget.org/packages/CSharpInteractive.Templates).\n\nCreate a console project *__Build__* containing a script from the template *__build__*\n\n```shell\ndotnet new build -o ./Build\n```\n\nThe created project contains 2 entry points:\n- _Program.csx_ to run as a script\n  ```shell\n  dotnet csi ./Build\n  ```\n- _Program.cs_ to run as .NET application\n  ```shell\n  dotnet run --project ./Build\n  ```\n\n\u003c/details\u003e\n\n## NuGet packages\n\n| Package name                | Link                                                                                                                                 | Description                                        | Installation                                   |\n|-----------------------------|--------------------------------------------------------------------------------------------------------------------------------------|:---------------------------------------------------|------------------------------------------------|\n| dotnet-csi                  | [![NuGet](https://img.shields.io/nuget/v/dotnet-csi)](https://www.nuget.org/packages/dotnet-csi)                                     | Interactive .NET tool for REPL and running scripts | dotnet tool install --global dotnet-csi        |\n| CSharpInteractive.Templates | [![NuGet](https://img.shields.io/nuget/v/CSharpInteractive.Templates )](https://www.nuget.org/packages/CSharpInteractive.Templates ) | .NET build project template                        | dotnet new install CSharpInteractive.Templates |\n| CSharpInteractive           | [![NuGet](https://img.shields.io/nuget/v/CSharpInteractive)](https://www.nuget.org/packages/CSharpInteractive)                       | A library for use in .NET build projects           | dotnet add package CSharpInteractive           |\n\n## Usage examples\n\n- [Build project example](https://github.com/DevTeam/csharp-interactive/tree/master/Samples/MySampleLib)\n- [CSharp Interactive build project](https://github.com/DevTeam/csharp-interactive/tree/master/Build)\n- [Pure.DI build project](https://github.com/DevTeam/Pure.DI/tree/master/build)\n- [Immutype build project](https://github.com/DevTeam/Immutype/tree/master/Build)\n- [Comparison with Cake and Nuke](https://github.com/DevTeam/ci-cd)\n\n## API\n\n- Output, logging and tracing\n  - [Writing a line to a build log](#writing-a-line-to-a-build-log)\n  - [Writing a line highlighted with \"Header\" color to a build log](#writing-a-line-highlighted-with-\"header\"-color-to-a-build-log)\n  - [Writing an empty line to a build log](#writing-an-empty-line-to-a-build-log)\n  - [Registering errors in the build log](#registering-errors-in-the-build-log)\n  - [Registering warnings in the build log](#registering-warnings-in-the-build-log)\n  - [Registering a summary in the build log](#registering-a-summary-in-the-build-log)\n  - [Registering information in the build log](#registering-information-in-the-build-log)\n  - [Registering trace information in the build log](#registering-trace-information-in-the-build-log)\n- Arguments and parameters\n  - [Command line arguments](#command-line-arguments)\n  - [Using properties](#using-properties)\n- Microsoft DI\n  - [Using the Host property](#using-the-host-property)\n  - [Getting services](#getting-services)\n  - [Using service collections](#using-service-collections)\n- NuGet\n  - [Restoring a NuGet package of newest version](#restoring-a-nuget-package-of-newest-version)\n  - [Restoring a NuGet package by a version range for the specified .NET and path](#restoring-a-nuget-package-by-a-version-range-for-the-specified-.net-and-path)\n- Command Line\n  - [Building custom command lines](#building-custom-command-lines)\n  - [Running a command line](#running-a-command-line)\n  - [Running a command line asynchronously](#running-a-command-line-asynchronously)\n  - [Running and analyzing an output](#running-and-analyzing-an-output)\n  - [Running asynchronously in parallel](#running-asynchronously-in-parallel)\n  - [Cancellation of asynchronous run](#cancellation-of-asynchronous-run)\n  - [Running with timeout](#running-with-timeout)\n- Docker CLI\n  - [Building a project in a docker container](#building-a-project-in-a-docker-container)\n  - [Running in docker](#running-in-docker)\n- .NET CLI\n  - [Adding a NuGet package](#adding-a-nuget-package)\n  - [Adding a NuGet source](#adding-a-nuget-source)\n  - [Adding a project reference](#adding-a-project-reference)\n  - [Adding projects to the solution file](#adding-projects-to-the-solution-file)\n  - [Adding project-to-project (P2P) references](#adding-project-to-project-(p2p)-references)\n  - [Building a project](#building-a-project)\n  - [Building a project using MSBuild](#building-a-project-using-msbuild)\n  - [Cleaning a project](#cleaning-a-project)\n  - [Clearing the specified NuGet cache type](#clearing-the-specified-nuget-cache-type)\n  - [Creating a new project, configuration file, or solution based on the specified template](#creating-a-new-project,-configuration-file,-or-solution-based-on-the-specified-template)\n  - [Deleting a NuGet package to the server](#deleting-a-nuget-package-to-the-server)\n  - [Disabling a NuGet source](#disabling-a-nuget-source)\n  - [Displaing template package metadata](#displaing-template-package-metadata)\n  - [Enabling a NuGet source](#enabling-a-nuget-source)\n  - [Enabling or disabling workload-set update mode](#enabling-or-disabling-workload-set-update-mode)\n  - [Executing a dotnet application](#executing-a-dotnet-application)\n  - [Fixing (non code style) analyzer issues](#fixing-(non-code-style)-analyzer-issues)\n  - [Fixing code style issues](#fixing-code-style-issues)\n  - [Formatting a code](#formatting-a-code)\n  - [Getting a value of a specified NuGet configuration setting](#getting-a-value-of-a-specified-nuget-configuration-setting)\n  - [Installing a template package](#installing-a-template-package)\n  - [Installing optional workloads](#installing-optional-workloads)\n  - [Installing the .NET local tools that are in scope for the current directory](#installing-the-.net-local-tools-that-are-in-scope-for-the-current-directory)\n  - [Installing the specified .NET tool](#installing-the-specified-.net-tool)\n  - [Installing workloads needed for a project or a solution](#installing-workloads-needed-for-a-project-or-a-solution)\n  - [Invoking a local tool](#invoking-a-local-tool)\n  - [Packing a code into a NuGet package](#packing-a-code-into-a-nuget-package)\n  - [Printing a dependency graph for NuGet package](#printing-a-dependency-graph-for-nuget-package)\n  - [Printing all .NET tools of the specified type currently installed](#printing-all-.net-tools-of-the-specified-type-currently-installed)\n  - [Printing all configured NuGet sources](#printing-all-configured-nuget-sources)\n  - [Printing all projects in a solution file](#printing-all-projects-in-a-solution-file)\n  - [Printing available templates to be run using dotnet new](#printing-available-templates-to-be-run-using-dotnet-new)\n  - [Printing installed workloads](#printing-installed-workloads)\n  - [Printing nuget configuration files currently being applied to a directory](#printing-nuget-configuration-files-currently-being-applied-to-a-directory)\n  - [Printing NuGet packages for a project](#printing-nuget-packages-for-a-project)\n  - [Printing project references for a project](#printing-project-references-for-a-project)\n  - [Printing the latest available version of the .NET SDK and .NET Runtime, for each feature band](#printing-the-latest-available-version-of-the-.net-sdk-and-.net-runtime,-for-each-feature-band)\n  - [Printing the location of the specified NuGet cache type](#printing-the-location-of-the-specified-nuget-cache-type)\n  - [Publishing an application and its dependencies to a folder for deployment to a hosting system](#publishing-an-application-and-its-dependencies-to-a-folder-for-deployment-to-a-hosting-system)\n  - [Pushing a NuGet package to the server](#pushing-a-nuget-package-to-the-server)\n  - [Removing a NuGet package](#removing-a-nuget-package)\n  - [Removing a project or multiple projects from the solution file](#removing-a-project-or-multiple-projects-from-the-solution-file)\n  - [Removing an existing source from your NuGet configuration files](#removing-an-existing-source-from-your-nuget-configuration-files)\n  - [Repairing workloads installations](#repairing-workloads-installations)\n  - [Restoring the dependencies and tools of a project](#restoring-the-dependencies-and-tools-of-a-project)\n  - [Running a .NET application](#running-a-.net-application)\n  - [Running a custom .NET command](#running-a-custom-.net-command)\n  - [Running source code without any explicit compile or launch commands](#running-source-code-without-any-explicit-compile-or-launch-commands)\n  - [Running tests from the specified assemblies](#running-tests-from-the-specified-assemblies)\n  - [Running tests under dotCover](#running-tests-under-dotcover)\n  - [Searching all .NET tools that are published to NuGet](#searching-all-.net-tools-that-are-published-to-nuget)\n  - [Searching for a NuGet package](#searching-for-a-nuget-package)\n  - [Searching for optional workloads](#searching-for-optional-workloads)\n  - [Searching for the templates](#searching-for-the-templates)\n  - [Setting the value of a specified NuGet configuration setting](#setting-the-value-of-a-specified-nuget-configuration-setting)\n  - [Signing with certificate](#signing-with-certificate)\n  - [Storing the specified assemblies in the runtime package store.](#storing-the-specified-assemblies-in-the-runtime-package-store.)\n  - [Testing a project using the MSBuild VSTest target](#testing-a-project-using-the-msbuild-vstest-target)\n  - [Testing from the specified project](#testing-from-the-specified-project)\n  - [Uninstalling a specified workload](#uninstalling-a-specified-workload)\n  - [Uninstalling a template package](#uninstalling-a-template-package)\n  - [Uninstalling the specified .NET tool](#uninstalling-the-specified-.net-tool)\n  - [Unsetting the value of a specified NuGet configuration setting](#unsetting-the-value-of-a-specified-nuget-configuration-setting)\n  - [Updating a NuGet source](#updating-a-nuget-source)\n  - [Updating installed template packages](#updating-installed-template-packages)\n  - [Updating installed workloads](#updating-installed-workloads)\n  - [Updating the specified .NET tool](#updating-the-specified-.net-tool)\n  - [Working with development certificates](#working-with-development-certificates)\n  - [Running C# script](#running-c#-script)\n  - [Shutting down build servers](#shutting-down-build-servers)\n- TeamCity API\n  - [TeamCity integration via service messages](#teamcity-integration-via-service-messages)\n\n## Output, logging and tracing\n\n### Writing a line to a build log\n\n``` CSharp\nWriteLine(\"Hello\");\n```\n\n### Writing a line highlighted with \"Header\" color to a build log\n\n``` CSharp\nWriteLine(\"Hello\", Header);\nWriteLine(\"Hello \".WithColor(Header), \"world!\");\n```\n\n### Writing an empty line to a build log\n\n``` CSharp\nWriteLine();\n```\n\n### Registering errors in the build log\n\n``` CSharp\nError(\"Error info\");\nError(\"Error info\", \"Error identifier\");\nError(\"Error: \".WithColor(), \"datails\".WithColor(Color.Details));\n```\n\n### Registering warnings in the build log\n\n``` CSharp\nWarning(\"Warning info\");\nWarning(\"Warning \", \"info\".WithColor(Color.Details));\n```\n\n### Registering a summary in the build log\n\n``` CSharp\nSummary(\"Summary message\");\nSummary(\"Summary \", \"message\".WithColor(Color.Details));\n```\n\n### Registering information in the build log\n\n``` CSharp\nInfo(\"Some info\");\nInfo(\"Some \", \"info\".WithColor(Color.Details));\n```\n\n### Registering trace information in the build log\n\n``` CSharp\nTrace(\"Some trace info\");\nTrace(\"Some trace \", \"info\".WithColor(Color.Details));\n```\n\n## Arguments and parameters\n\n### Command line arguments\n_Args_ have got from the script arguments.\n``` CSharp\nif (Args.Count \u003e 0)\n{\n    WriteLine(Args[0]);\n}\n\nif (Args.Count \u003e 1)\n{\n    WriteLine(Args[1]);\n}\n```\n\n### Using properties\n\n``` CSharp\nWriteLine(Props[\"version\"]);\nWriteLine(Props.Get(\"configuration\", \"Release\"));\n\n// Some CI/CDs have integration of these properties.\n// For example in TeamCity this property with all changes will be available in the next TeamCity steps.\nProps[\"version\"] = \"1.1.6\";\n```\n\n## Microsoft DI\n\n### Using the Host property\n[_Host_](TeamCity.CSharpInteractive.HostApi/IHost.cs) is actually the provider of all global properties and methods.\n``` CSharp\nvar packages = Host.GetService\u003cINuGet\u003e();\nHost.WriteLine(\"Hello\");\n```\n\n### Getting services\nThis method might be used to get access to different APIs like [INuGet](TeamCity.CSharpInteractive.HostApi/INuGet.cs) or [ICommandLine](TeamCity.CSharpInteractive.HostApi/ICommandLine.cs).\n``` CSharp\nGetService\u003cINuGet\u003e();\n\nvar serviceProvider = GetService\u003cIServiceProvider\u003e();\nserviceProvider.GetService(typeof(INuGet));\n```\nBesides that, it is possible to get an instance of [System.IServiceProvider](https://docs.microsoft.com/en-US/dotnet/api/system.iserviceprovider) to access APIs.\n### Using service collections\n\n``` CSharp\npublic void Run()\n{\n    var serviceProvider =\n        GetService\u003cIServiceCollection\u003e()\n            .AddTransient\u003cMyTask\u003e()\n            .BuildServiceProvider();\n\n    var myTask = serviceProvider.GetRequiredService\u003cMyTask\u003e();\n    var exitCode = myTask.Run();\n    exitCode.ShouldBe(0);\n}\n\nprivate class MyTask(ICommandLineRunner runner)\n{\n    public int? Run() =\u003e runner\n        .Run(new CommandLine(\"whoami\"))\n        .EnsureSuccess()\n        .ExitCode;\n}\n\n```\n\n## NuGet\n\n### Restoring a NuGet package of newest version\n\n``` CSharp\nusing HostApi;\n\nIEnumerable\u003cNuGetPackage\u003e packages = GetService\u003cINuGet\u003e()\n    .Restore(new NuGetRestoreSettings(\"IoC.Container\").WithVersionRange(VersionRange.All));\n```\n\n### Restoring a NuGet package by a version range for the specified .NET and path\n\n``` CSharp\nusing HostApi;\n\nvar packagesPath = Path.Combine(\n    Path.GetTempPath(),\n    Guid.NewGuid().ToString()[..4]);\n\nvar settings = new NuGetRestoreSettings(\"IoC.Container\")\n    .WithVersionRange(VersionRange.Parse(\"[1.3, 1.3.8)\"))\n    .WithTargetFrameworkMoniker(\"net5.0\")\n    .WithPackagesPath(packagesPath);\n\nIEnumerable\u003cNuGetPackage\u003e packages = GetService\u003cINuGet\u003e().Restore(settings);\n```\n\n## Command Line\n\n### Building custom command lines\n\n``` CSharp\nusing HostApi;\n\n// Creates and run a simple command line \n\"whoami\".AsCommandLine().Run().EnsureSuccess();\n\n// Creates and run a simple command line \nnew CommandLine(\"whoami\").Run().EnsureSuccess();\n\n// Creates and run a command line with arguments \nnew CommandLine(\"cmd\", \"/c\", \"echo\", \"Hello\").Run();\n\n// Same as previous statement\nnew CommandLine(\"cmd\", \"/c\")\n    .AddArgs(\"echo\", \"Hello\")\n    .Run().EnsureSuccess();\n\n(new CommandLine(\"cmd\") + \"/c\" + \"echo\" + \"Hello\")\n    .Run().EnsureSuccess();\n\n\"cmd\".AsCommandLine(\"/c\", \"echo\", \"Hello\")\n    .Run().EnsureSuccess();\n\n(\"cmd\".AsCommandLine() + \"/c\" + \"echo\" + \"Hello\")\n    .Run().EnsureSuccess();\n\n// Just builds a command line with multiple environment variables\nvar cmd = new CommandLine(\"cmd\", \"/c\", \"echo\", \"Hello\")\n    .AddVars((\"Var1\", \"val1\"), (\"var2\", \"Val2\"));\n\n// Same as previous statement\ncmd = new CommandLine(\"cmd\") + \"/c\" + \"echo\" + \"Hello\" + (\"Var1\", \"val1\") + (\"var2\", \"Val2\");\n\n// Builds a command line to run from a specific working directory \ncmd = new CommandLine(\"cmd\", \"/c\", \"echo\", \"Hello\")\n    .WithWorkingDirectory(\"MyDyrectory\");\n\n// Builds a command line and replaces all command line arguments\ncmd = new CommandLine(\"cmd\", \"/c\", \"echo\", \"Hello\")\n    .WithArgs(\"/c\", \"echo\", \"Hello !!!\");\n```\n\n### Running a command line\n\n``` CSharp\nusing HostApi;\n\nGetService\u003cICommandLineRunner\u003e()\n    .Run(new CommandLine(\"cmd\", \"/c\", \"DIR\")).EnsureSuccess();\n\n// or the same thing using the extension method\nnew CommandLine(\"cmd\", \"/c\", \"DIR\")\n    .Run().EnsureSuccess();\n\n// using operator '+'\nvar cmd = new CommandLine(\"cmd\") + \"/c\" + \"DIR\";\ncmd.Run().EnsureSuccess();\n\n// with environment variables\ncmd = new CommandLine(\"cmd\") + \"/c\" + \"DIR\" + (\"MyEnvVar\", \"Some Value\");\ncmd.Run().EnsureSuccess();\n```\n\n### Running a command line asynchronously\n\n``` CSharp\nusing HostApi;\n\nawait GetService\u003cICommandLineRunner\u003e()\n    .RunAsync(new CommandLine(\"cmd\", \"/C\", \"DIR\")).EnsureSuccess();\n\n// or the same thing using the extension method\nvar result = await new CommandLine(\"cmd\", \"/c\", \"DIR\")\n    .RunAsync().EnsureSuccess();\n```\n\n### Running and analyzing an output\n\n``` CSharp\nusing HostApi;\n\nvar lines = new List\u003cstring\u003e();\nvar result = new CommandLine(\"cmd\", \"/c\", \"SET\")\n    .AddVars((\"MyEnv\", \"MyVal\"))\n    .Run(output =\u003e lines.Add(output.Line)).EnsureSuccess();\n\nlines.ShouldContain(\"MyEnv=MyVal\");\n```\n\n### Running asynchronously in parallel\n\n``` CSharp\nusing HostApi;\n\nvar task = new CommandLine(\"cmd\", \"/c\", \"DIR\")\n    .RunAsync().EnsureSuccess();\n\nvar result = new CommandLine(\"cmd\", \"/c\", \"SET\")\n    .Run().EnsureSuccess();\n\nawait task;\n```\n\n### Cancellation of asynchronous run\nCancellation will destroy the process and its child processes.\n``` CSharp\nusing HostApi;\n\nvar cancellationTokenSource = new CancellationTokenSource();\nvar task = new CommandLine(\"cmd\", \"/c\", \"TIMEOUT\", \"/T\", \"120\")\n    .RunAsync(null, cancellationTokenSource.Token);\n\ncancellationTokenSource.CancelAfter(TimeSpan.FromMilliseconds(100));\ntask.IsCompleted.ShouldBeFalse();\n```\n\n### Running with timeout\nIf timeout expired a process will be killed.\n``` CSharp\nusing HostApi;\n\nvar exitCode = new CommandLine(\"cmd\", \"/c\", \"TIMEOUT\", \"/T\", \"120\")\n    .Run(null, TimeSpan.FromMilliseconds(1))\n    .ExitCode;\n```\n\n## Docker CLI\n\n### Building a project in a docker container\n\n``` CSharp\nusing HostApi;\n\n// Creates a base docker command line\nvar dockerRun = new DockerRun()\n    .WithAutoRemove(true)\n    .WithInteractive(true)\n    .WithImage(\"mcr.microsoft.com/dotnet/sdk\")\n    .WithPlatform(\"linux\")\n    .WithContainerWorkingDirectory(\"/MyProjects\")\n    .AddVolumes((ToAbsoluteLinuxPath(Environment.CurrentDirectory), \"/MyProjects\"));\n\n// Creates a new library project in a docker container\ndockerRun\n    .WithCommandLine(new DotNetCustom(\"new\", \"classlib\", \"-n\", \"MyLib\", \"--force\"))\n    .Run().EnsureSuccess();\n\n// Builds the library project in a docker container\nvar result = dockerRun\n    .WithCommandLine(new DotNetBuild().WithProject(\"MyLib/MyLib.csproj\"))\n    .Build().EnsureSuccess();\n\nstring ToAbsoluteLinuxPath(string path) =\u003e\n    \"/\" + path.Replace(\":\", \"\").Replace('\\\\', '/');\n```\n\n### Running in docker\n\n``` CSharp\nusing HostApi;\n\n// Creates some command line to run in a docker container\nvar cmd = new CommandLine(\"whoami\");\n\n// Runs the command line in a docker container\nvar result = new DockerRun(cmd, \"mcr.microsoft.com/dotnet/sdk\")\n    .WithAutoRemove(true)\n    .Run().EnsureSuccess();\n```\n\n## .NET CLI\n\n### Adding a NuGet package\n\n``` CSharp\nusing HostApi;\n\nvar result = new DotNetAddPackage()\n    .WithWorkingDirectory(\"MyLib\")\n    .WithPackage(\"Pure.DI\")\n    .Run().EnsureSuccess();\n```\n\n### Adding a NuGet source\n\n``` CSharp\nusing HostApi;\n\nnew DotNetNuGetAddSource()\n    .WithName(\"TestSource\")\n    .WithSource(source)\n    .Run().EnsureSuccess();\n```\n\n### Adding a project reference\n\n``` CSharp\nusing HostApi;\n\nnew DotNetAddReference()\n    .WithProject(Path.Combine(\"MyTests\", \"MyTests.csproj\"))\n    .WithReferences(Path.Combine(\"MyLib\", \"MyLib.csproj\"))\n    .Run().EnsureSuccess();\n\nnew DotNetRemoveReference()\n    .WithProject(Path.Combine(\"MyTests\", \"MyTests.csproj\"))\n    .WithReferences(Path.Combine(\"MyLib\", \"MyLib.csproj\"))\n    .Run().EnsureSuccess();\n\nvar lines = new List\u003cstring\u003e();\nnew DotNetListReference()\n    .WithProject(Path.Combine(\"MyTests\", \"MyTests.csproj\"))\n    .Run(output =\u003e lines.Add(output.Line));\n\nlines.Any(i =\u003e i.Contains(\"MyLib.csproj\")).ShouldBeFalse();\n```\n\n### Adding projects to the solution file\n\n``` CSharp\nusing HostApi;\n\nnew DotNetNew()\n    .WithTemplateName(\"sln\")\n    .WithName(\"NySolution\")\n    .WithForce(true)\n    .Run().EnsureSuccess();\n\nnew DotNetSlnAdd()\n    .WithSolution(\"NySolution.sln\")\n    .AddProjects(\n        Path.Combine(\"MyLib\", \"MyLib.csproj\"),\n        Path.Combine(\"MyTests\", \"MyTests.csproj\"))\n    .Run().EnsureSuccess();\n```\n\n### Adding project-to-project (P2P) references\n\n``` CSharp\nusing HostApi;\n\nvar result = new DotNetAddReference()\n    .WithProject(Path.Combine(\"MyTests\", \"MyTests.csproj\"))\n    .WithReferences(Path.Combine(\"MyLib\", \"MyLib.csproj\"))\n    .Run().EnsureSuccess();\n\n```\n\n### Building a project\n\n``` CSharp\nusing HostApi;\n\nvar messages = new List\u003cBuildMessage\u003e();\nvar result = new DotNetBuild()\n    .WithWorkingDirectory(\"MyTests\")\n    .Build(message =\u003e messages.Add(message)).EnsureSuccess();\n\nresult.Errors.Any(message =\u003e message.State == BuildMessageState.StdError).ShouldBeFalse(result.ToString());\nresult.ExitCode.ShouldBe(0, result.ToString());\n```\n\n### Building a project using MSBuild\n\n``` CSharp\nusing HostApi;\n\n// Creates a new library project, running a command like: \"dotnet new classlib -n MyLib --force\"\nnew DotNetNew()\n    .WithTemplateName(\"classlib\")\n    .WithName(\"MyLib\")\n    .WithForce(true)\n    .Build().EnsureSuccess();\n\n// Builds the library project, running a command like: \"dotnet msbuild /t:Build -restore /p:configuration=Release -verbosity=detailed\" from the directory \"MyLib\"\nvar result = new MSBuild()\n    .WithWorkingDirectory(\"MyLib\")\n    .WithTarget(\"Build\")\n    .WithRestore(true)\n    .AddProps((\"configuration\", \"Release\"))\n    .WithVerbosity(DotNetVerbosity.Detailed)\n    .Build().EnsureSuccess();\n\n// The \"result\" variable provides details about a build\nresult.Errors.Any(message =\u003e message.State == BuildMessageState.StdError).ShouldBeFalse(result.ToString());\nresult.ExitCode.ShouldBe(0, result.ToString());\n```\n\n### Cleaning a project\n\n``` CSharp\nusing HostApi;\n\n// Clean the project, running a command like: \"dotnet clean\" from the directory \"MyLib\"\nnew DotNetClean()\n    .WithWorkingDirectory(\"MyLib\")\n    .Build().EnsureSuccess();\n```\n\n### Clearing the specified NuGet cache type\n\n``` CSharp\nusing HostApi;\n\nnew DotNetNuGetLocalsClear()\n    .WithCacheLocation(NuGetCacheLocation.Temp)\n    .Run().EnsureSuccess();\n```\n\n### Creating a new project, configuration file, or solution based on the specified template\n\n``` CSharp\nusing HostApi;\n\nnew DotNetNew()\n    .WithTemplateName(\"classlib\")\n    .WithName(\"MyLib\")\n    .WithForce(true)\n    .Run().EnsureSuccess();\n```\n\n### Deleting a NuGet package to the server\n\n``` CSharp\nusing HostApi;\n\nnew DotNetNuGetDelete()\n    .WithPackage(\"MyLib\")\n    .WithPackageVersion(\"1.0.0\")\n    .WithSource(repoUrl)\n    .Run().EnsureSuccess();\n```\n\n### Disabling a NuGet source\n\n``` CSharp\nusing HostApi;\n\nnew DotNetNuGetDisableSource()\n    .WithName(\"TestSource\")\n    .Run().EnsureSuccess();\n```\n\n### Displaing template package metadata\n\n``` CSharp\nusing HostApi;\n\nnew DotNetNewDetails()\n    .WithTemplateName(\"CSharpInteractive.Templates\")\n    .Run().EnsureSuccess();\n```\n\n### Enabling a NuGet source\n\n``` CSharp\nusing HostApi;\n\nnew DotNetNuGetEnableSource()\n    .WithName(\"TestSource\")\n    .Run().EnsureSuccess();\n```\n\n### Enabling or disabling workload-set update mode\n\n``` CSharp\nusing HostApi;\n\nnew DotNetWorkloadConfig()\n    .WithUpdateMode(DotNetWorkloadUpdateMode.WorkloadSet)\n    .Run().EnsureSuccess();\n```\n\n### Executing a dotnet application\n\n``` CSharp\nusing HostApi;\nnew DotNetExec()\n    .WithPathToApplication(Path.Combine(path, \"MyApp.dll\"))\n    .Run().EnsureSuccess();\n```\n\n### Fixing (non code style) analyzer issues\n\n``` CSharp\nusing HostApi;\n\nnew DotNetFormatAnalyzers()\n    .WithWorkingDirectory(\"MyLib\")\n    .WithProject(\"MyLib.csproj\")\n    .AddDiagnostics(\"CA1831\", \"CA1832\")\n    .WithSeverity(DotNetFormatSeverity.Warning)\n    .Run().EnsureSuccess();\n```\n\n### Fixing code style issues\n\n``` CSharp\nusing HostApi;\n\nnew DotNetFormatStyle()\n    .WithWorkingDirectory(\"MyLib\")\n    .WithProject(\"MyLib.csproj\")\n    .AddDiagnostics(\"IDE0005\", \"IDE0006\")\n    .WithSeverity(DotNetFormatSeverity.Information)\n    .Run().EnsureSuccess();\n```\n\n### Formatting a code\n\n``` CSharp\nusing HostApi;\n\nnew DotNetFormat()\n    .WithWorkingDirectory(\"MyLib\")\n    .WithProject(\"MyLib.csproj\")\n    .AddDiagnostics(\"IDE0005\", \"IDE0006\")\n    .AddIncludes(\".\", \"./tests\")\n    .AddExcludes(\"./obj\")\n    .WithSeverity(DotNetFormatSeverity.Information)\n    .Run().EnsureSuccess();\n```\n\n### Getting a value of a specified NuGet configuration setting\n\n``` CSharp\nusing HostApi;\n\nstring? repositoryPath = null;\nnew DotNetNuGetConfigGet()\n    .WithConfigKey(\"repositoryPath\")\n    .Run(output =\u003e repositoryPath = output.Line).EnsureSuccess();\n```\n\n### Installing a template package\n\n``` CSharp\nusing HostApi;\n\nnew DotNetNewInstall()\n    .WithPackage(\"Pure.DI.Templates\")\n    .Run().EnsureSuccess();\n```\n\n### Installing optional workloads\n\n``` CSharp\nusing HostApi;\n\nnew DotNetWorkloadInstall()\n    .AddWorkloads(\"aspire\")\n    .Run().EnsureSuccess();\n```\n\n### Installing the .NET local tools that are in scope for the current directory\n\n``` CSharp\nusing HostApi;\n\n// Creates a local tool manifest \nnew DotNetNew()\n    .WithTemplateName(\"tool-manifest\")\n    .Run().EnsureSuccess();\n\nnew DotNetToolRestore()\n    .Run().EnsureSuccess();\n```\n\n### Installing the specified .NET tool\n\n``` CSharp\nusing HostApi;\n\nnew DotNetToolInstall()\n    .WithLocal(true)\n    .WithPackage(\"dotnet-csi\")\n    .WithVersion(\"1.1.2\")\n    .Run().EnsureSuccess();\n```\n\n### Installing workloads needed for a project or a solution\n\n``` CSharp\nusing HostApi;\n\nnew DotNetWorkloadRestore()\n    .WithProject(Path.Combine(\"MyLib\", \"MyLib.csproj\"))\n    .Run().EnsureSuccess();\n```\n\n### Invoking a local tool\n\n``` CSharp\nusing HostApi;\n\nvar script = Path.GetTempFileName();\nFile.WriteAllText(script, \"Console.WriteLine($\\\"Hello, {Args[0]}!\\\");\");\n\nvar stdOut = new List\u003cstring\u003e();\nnew DotNetToolRun()\n    .WithCommandName(\"dotnet-csi\")\n    .AddArgs(script)\n    .AddArgs(\"World\")\n    .Run(output =\u003e stdOut.Add(output.Line))\n    .EnsureSuccess();\n\n// Checks stdOut\nstdOut.Contains(\"Hello, World!\").ShouldBeTrue();\n```\n\n### Packing a code into a NuGet package\n\n``` CSharp\nusing HostApi;\n\n// Creates a NuGet package of version 1.2.3 for the project\nnew DotNetPack()\n    .WithWorkingDirectory(\"MyLib\")\n    .WithOutput(path)\n    .AddProps((\"version\", \"1.2.3\"))\n    .Build().EnsureSuccess();\n```\n\n### Printing a dependency graph for NuGet package\n\n``` CSharp\nusing HostApi;\n\nnew DotNetNuGetWhy()\n    .WithProject(Path.Combine(\"MyLib\", \"MyLib.csproj\"))\n    .WithPackage(\"MyLib.1.2.3.nupkg\")\n    .Run().EnsureSuccess();\n```\n\n### Printing all .NET tools of the specified type currently installed\n\n``` CSharp\nusing HostApi;\n\nnew DotNetToolList()\n    .WithLocal(true)\n    .Run().EnsureSuccess();\n\nnew DotNetToolList()\n    .WithGlobal(true)\n    .Run().EnsureSuccess();\n```\n\n### Printing all configured NuGet sources\n\n``` CSharp\nusing HostApi;\n\nnew DotNetNuGetListSource()\n    .WithFormat(NuGetListFormat.Short)\n    .Run().EnsureSuccess();\n```\n\n### Printing all projects in a solution file\n\n``` CSharp\nusing HostApi;\n\nvar lines = new List\u003cstring\u003e();\nnew DotNetSlnList()\n    .WithSolution(\"NySolution.sln\")\n    .Run(output =\u003e lines.Add(output.Line))\n    .EnsureSuccess();\n```\n\n### Printing available templates to be run using dotnet new\n\n``` CSharp\nusing HostApi;\n\nnew DotNetNewList()\n    .Run().EnsureSuccess();\n```\n\n### Printing installed workloads\n\n``` CSharp\nusing HostApi;\n\nnew DotNetWorkloadList()\n    .Run().EnsureSuccess();\n```\n\n### Printing nuget configuration files currently being applied to a directory\n\n``` CSharp\nusing HostApi;\n\nvar configPaths = new List\u003cstring\u003e();\nnew DotNetNuGetConfigPaths()\n    .Run(output =\u003e configPaths.Add(output.Line)).EnsureSuccess();\n```\n\n### Printing NuGet packages for a project\n\n``` CSharp\nusing HostApi;\n\nnew DotNetAddPackage()\n    .WithWorkingDirectory(\"MyLib\")\n    .WithPackage(\"Pure.DI\")\n    .Run().EnsureSuccess();\n\nvar lines = new List\u003cstring\u003e();\nnew DotNetListPackage()\n    .WithProject(Path.Combine(\"MyLib\", \"MyLib.csproj\"))\n    .WithVerbosity(DotNetVerbosity.Minimal)\n    .Run(output =\u003e lines.Add(output.Line));\n\nlines.Any(i =\u003e i.Contains(\"Pure.DI\")).ShouldBeTrue();\n```\n\n### Printing project references for a project\n\n``` CSharp\nusing HostApi;\n\nnew DotNetAddReference()\n    .WithProject(Path.Combine(\"MyTests\", \"MyTests.csproj\"))\n    .WithReferences(Path.Combine(\"MyLib\", \"MyLib.csproj\"))\n    .Run().EnsureSuccess();\n\nvar lines = new List\u003cstring\u003e();\nnew DotNetListReference()\n    .WithProject(Path.Combine(\"MyTests\", \"MyTests.csproj\"))\n    .Run(output =\u003e lines.Add(output.Line));\n\nlines.Any(i =\u003e i.Contains(\"MyLib.csproj\")).ShouldBeTrue();\n```\n\n### Printing the latest available version of the .NET SDK and .NET Runtime, for each feature band\n\n``` CSharp\nusing HostApi;\n\nvar sdks = new List\u003cSdk\u003e();\nnew DotNetSdkCheck()\n    .Run(output =\u003e\n    {\n        if (output.Line.StartsWith(\"Microsoft.\"))\n        {\n            var data = output.Line.Split(' ', StringSplitOptions.RemoveEmptyEntries);\n            if (data.Length \u003e= 2)\n            {\n                sdks.Add(new Sdk(data[0], NuGetVersion.Parse(data[1])));\n            }\n        }\n    })\n    .EnsureSuccess();\n\nsdks.Count.ShouldBeGreaterThan(0);\n\nrecord Sdk(string Name, NuGetVersion Version);\n```\n\n### Printing the location of the specified NuGet cache type\n\n``` CSharp\nusing HostApi;\n\nnew DotNetNuGetLocalsList()\n    .WithCacheLocation(NuGetCacheLocation.GlobalPackages)\n    .Run().EnsureSuccess();\n```\n\n### Publishing an application and its dependencies to a folder for deployment to a hosting system\n\n``` CSharp\nusing HostApi;\n\nnew DotNetPublish()\n    .WithWorkingDirectory(\"MyLib\")\n    .WithFramework(framework)\n    .WithOutput(\"bin\")\n    .Build().EnsureSuccess();\n```\n\n### Pushing a NuGet package to the server\n\n``` CSharp\nusing HostApi;\n\nnew DotNetNuGetPush()\n    .WithWorkingDirectory(\"MyLib\")\n    .WithPackage(Path.Combine(\"packages\", \"MyLib.1.0.0.nupkg\"))\n    .WithSource(repoUrl)\n    .Run().EnsureSuccess();\n```\n\n### Removing a NuGet package\n\n``` CSharp\nusing HostApi;\n\nnew DotNetAddPackage()\n    .WithWorkingDirectory(\"MyLib\")\n    .WithPackage(\"Pure.DI\")\n    .Run().EnsureSuccess();\n\nnew DotNetRemovePackage()\n    .WithWorkingDirectory(\"MyLib\")\n    .WithPackage(\"Pure.DI\")\n    .Run().EnsureSuccess();\n```\n\n### Removing a project or multiple projects from the solution file\n\n``` CSharp\nusing HostApi;\n\nnew DotNetSlnRemove()\n    .WithSolution(\"NySolution.sln\")\n    .AddProjects(\n        Path.Combine(\"MyLib\", \"MyLib.csproj\"))\n    .Run().EnsureSuccess();\n```\n\n### Removing an existing source from your NuGet configuration files\n\n``` CSharp\nusing HostApi;\n\nnew DotNetNuGetRemoveSource()\n    .WithName(\"TestSource\")\n    .Run().EnsureSuccess(); \n```\n\n### Repairing workloads installations\n\n``` CSharp\nusing HostApi;\n\nnew DotNetWorkloadRepair()\n    .Run().EnsureSuccess();\n```\n\n### Restoring the dependencies and tools of a project\n\n``` CSharp\nusing HostApi;\n\nnew DotNetRestore()\n    .WithProject(Path.Combine(\"MyLib\", \"MyLib.csproj\"))\n    .Build().EnsureSuccess();\n```\n\n### Running a .NET application\n\n``` CSharp\n// Adds the namespace \"HostApi\" to use .NET build API\nusing HostApi;\n\nnew DotNet()\n    .WithPathToApplication(Path.Combine(path, \"MyApp.dll\"))\n    .Run().EnsureSuccess();\n```\n\n### Running a custom .NET command\n\n``` CSharp\nusing HostApi;\n\n// Gets the dotnet version, running a command like: \"dotnet --version\"\nNuGetVersion? version = null;\nnew DotNetCustom(\"--version\")\n    .Run(message =\u003e NuGetVersion.TryParse(message.Line, out version))\n    .EnsureSuccess();\n\nversion.ShouldNotBeNull();\n```\n\n### Running source code without any explicit compile or launch commands\n\n``` CSharp\nusing HostApi;\n\nvar stdOut = new List\u003cstring\u003e();\nnew DotNetRun()\n    .WithProject(Path.Combine(\"MyApp\", \"MyApp.csproj\"))\n    .Build(message =\u003e stdOut.Add(message.Text))\n    .EnsureSuccess();\n```\n\n### Running tests from the specified assemblies\n\n``` CSharp\nusing HostApi;\n\n// Runs tests\nvar result = new VSTest()\n    .AddTestFileNames(Path.Combine(\"bin\", \"MyTests.dll\"))\n    .WithWorkingDirectory(path)\n    .Build().EnsureSuccess();\n\n// The \"result\" variable provides details about build and tests\nresult.ExitCode.ShouldBe(0, result.ToString());\nresult.Summary.Tests.ShouldBe(1, result.ToString());\nresult.Tests.Count(test =\u003e test.State == TestState.Finished).ShouldBe(1, result.ToString());\n```\n\n### Running tests under dotCover\n\n``` CSharp\nusing HostApi;\n\nnew DotNetToolInstall()\n    .WithLocal(true)\n    .WithPackage(\"JetBrains.dotCover.GlobalTool\")\n    .Run().EnsureSuccess();\n\n// Creates a test command\nvar test = new DotNetTest()\n    .WithProject(\"MyTests\");\n\nvar dotCoverSnapshot = Path.Combine(\"MyTests\", \"dotCover.dcvr\");\nvar dotCoverReport = Path.Combine(\"MyTests\", \"dotCover.html\");\n// Modifies the test command by putting \"dotCover\" in front of all arguments\n// to have something like \"dotnet dotcover test ...\"\n// and adding few specific arguments to the end\nvar testUnderDotCover = test.Customize(cmd =\u003e\n    cmd.ClearArgs()\n    + \"dotcover\"\n    + cmd.Args\n    + $\"--dcOutput={dotCoverSnapshot}\"\n    + \"--dcFilters=+:module=TeamCity.CSharpInteractive.HostApi;+:module=dotnet-csi\"\n    + \"--dcAttributeFilters=System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage\");\n\n// Runs tests under dotCover\nvar result = testUnderDotCover\n    .Build().EnsureSuccess();\n\n// The \"result\" variable provides details about a build\nresult.ExitCode.ShouldBe(0, result.ToString());\nresult.Tests.Count(i =\u003e i.State == TestState.Finished).ShouldBe(1, result.ToString());\n\n// Generates a HTML code coverage report.\nnew DotNetCustom(\"dotCover\", \"report\", $\"--source={dotCoverSnapshot}\", $\"--output={dotCoverReport}\", \"--reportType=HTML\")\n    .Run().EnsureSuccess();\n```\n\n### Searching all .NET tools that are published to NuGet\n\n``` CSharp\nusing HostApi;\n\nnew DotNetToolSearch()\n    .WithPackage(\"dotnet-csi\")\n    .WithDetail(true)\n    .Run().EnsureSuccess();\n```\n\n### Searching for a NuGet package\n\n``` CSharp\nusing System.Text;\nusing System.Text.Json;\nusing HostApi;\n\nvar packagesJson = new StringBuilder();\nnew DotNetPackageSearch()\n    .WithSearchTerm(\"Pure.DI\")\n    .WithFormat(DotNetPackageSearchResultFormat.Json)\n    .Run(output =\u003e packagesJson.AppendLine(output.Line)).EnsureSuccess();\n\nvar result = JsonSerializer.Deserialize\u003cResult\u003e(\n    packagesJson.ToString(),\n    new JsonSerializerOptions { PropertyNameCaseInsensitive = true });\n\nresult.ShouldNotBeNull();\nresult.SearchResult.SelectMany(i =\u003e i.Packages).Count(i =\u003e i.Id == \"Pure.DI\").ShouldBe(1);\n\nrecord Result(int Version, IReadOnlyCollection\u003cSource\u003e SearchResult);\n\nrecord Source(string SourceName, IReadOnlyCollection\u003cPackage\u003e Packages);\n\nrecord Package(\n    string Id,\n    string LatestVersion,\n    int TotalDownloads,\n    string Owners);\n```\n\n### Searching for optional workloads\n\n``` CSharp\nusing HostApi;\n\nnew DotNetWorkloadSearch()\n    .WithSearchString(\"maui\")\n    .Run().EnsureSuccess();\n```\n\n### Searching for the templates\n\n``` CSharp\nusing HostApi;\n\nnew DotNetNewSearch()\n    .WithTemplateName(\"build\")\n    .Run().EnsureSuccess();\n```\n\n### Setting the value of a specified NuGet configuration setting\n\n``` CSharp\nusing HostApi;\n\nnew DotNetNuGetConfigSet()\n    .WithConfigFile(configFile)\n    .WithConfigKey(\"repositoryPath\")\n    .WithConfigValue(\"MyValue\")\n    .Run().EnsureSuccess();\n```\n\n### Signing with certificate\n\n``` CSharp\nusing HostApi;\n\nnew DotNetNuGetSign()\n    .AddPackages(\"MyLib.1.2.3.nupkg\")\n    .WithCertificatePath(\"certificate.pfx\")\n    .WithCertificatePassword(\"Abc\")\n    .WithTimestampingServer(\"http://timestamp.digicert.com/\")\n    .Run().EnsureSuccess();\n```\n\n### Storing the specified assemblies in the runtime package store.\n\n``` CSharp\nusing HostApi;\n\nnew DotNetStore()\n    .AddManifests(Path.Combine(\"MyLib\", \"MyLib.csproj\"))\n    .WithFramework(\"net8.0\")\n    .WithRuntime(\"win-x64\")\n    .Build();\n\n```\n\n### Testing a project using the MSBuild VSTest target\n\n``` CSharp\nusing HostApi;\n\n// Runs tests via a command\nvar result = new MSBuild()\n    .WithTarget(\"VSTest\")\n    .WithWorkingDirectory(\"MyTests\")\n    .Build().EnsureSuccess();\n\n// The \"result\" variable provides details about a build\nresult.ExitCode.ShouldBe(0, result.ToString());\nresult.Summary.Tests.ShouldBe(1, result.ToString());\nresult.Tests.Count(test =\u003e test.State == TestState.Finished).ShouldBe(1, result.ToString());\n```\n\n### Testing from the specified project\n\n``` CSharp\nusing HostApi;\n\n// Runs tests\nvar result = new DotNetTest()\n    .WithProject(\"MyTests\")\n    .Build().EnsureSuccess();\n```\n\n### Uninstalling a specified workload\n\n``` CSharp\nusing HostApi;\n\nnew DotNetWorkloadUninstall()\n    .AddWorkloads(\"aspire\")\n    .Run().EnsureSuccess();\n```\n\n### Uninstalling a template package\n\n``` CSharp\nusing HostApi;\n\nnew DotNetNewUninstall()\n    .WithPackage(\"Pure.DI.Templates\")\n    .Run();\n```\n\n### Uninstalling the specified .NET tool\n\n``` CSharp\nusing HostApi;\n\nnew DotNetToolUninstall()\n    .WithPackage(\"dotnet-csi\")\n    .Run().EnsureSuccess();\n```\n\n### Unsetting the value of a specified NuGet configuration setting\n\n``` CSharp\nusing HostApi;\n\nnew DotNetNuGetConfigUnset()\n    .WithConfigKey(\"repositoryPath\")\n    .Run().EnsureSuccess();\n```\n\n### Updating a NuGet source\n\n``` CSharp\nusing HostApi;\n\nnew DotNetNuGetUpdateSource()\n    .WithName(\"TestSource\")\n    .WithSource(newSource)\n    .Run().EnsureSuccess();\n```\n\n### Updating installed template packages\n\n``` CSharp\nusing HostApi;\n\nnew DotNetNewUpdate()\n    .Run().EnsureSuccess();\n```\n\n### Updating installed workloads\n\n``` CSharp\nusing HostApi;\n\nnew DotNetWorkloadUpdate()\n    .Run().EnsureSuccess();\n```\n\n### Updating the specified .NET tool\n\n``` CSharp\nusing HostApi;\n\nnew DotNetToolUpdate()\n    .WithLocal(true)\n    .WithPackage(\"dotnet-csi\")\n    .WithVersion(\"1.1.2\")\n    .Run().EnsureSuccess();\n```\n\n### Working with development certificates\n\n``` CSharp\nusing HostApi;\n\n// Create a certificate, trust it, and export it to a PEM file.\nnew DotNetDevCertsHttps()\n    .WithExportPath(\"certificate.pem\")\n    .WithTrust(true)\n    .WithFormat(DotNetCertificateFormat.Pem)\n    .WithPassword(\"Abc\")\n    .Run().EnsureSuccess();\n```\n\n### Running C# script\n\n``` CSharp\nusing HostApi;\n\nvar script = Path.GetTempFileName();\nFile.WriteAllText(script, \"Console.WriteLine($\\\"Hello, {Args[0]}!\\\");\");\n\nvar stdOut = new List\u003cstring\u003e();\nnew DotNetCsi()\n    .WithScript(script)\n    .AddArgs(\"World\")\n    .Run(output =\u003e stdOut.Add(output.Line))\n    .EnsureSuccess();\n\n// Checks stdOut\nstdOut.Contains(\"Hello, World!\").ShouldBeTrue();\n```\n\n### Shutting down build servers\n\n``` CSharp\nusing HostApi;\n\n// Shuts down all build servers that are started from dotnet.\nnew DotNetBuildServerShutdown()\n    .Run().EnsureSuccess();\n```\n\n## TeamCity API\n\n### TeamCity integration via service messages\nFor more details how to use TeamCity service message API please see [this](https://github.com/JetBrains/TeamCity.ServiceMessages) page. Instead of creating a root message writer like in the following example:\n``` CSharp\nusing JetBrains.TeamCity.ServiceMessages.Write.Special;\nusing var writer = new TeamCityServiceMessages().CreateWriter(Console.WriteLine);\n```\nuse this statement:\n``` CSharp\nusing JetBrains.TeamCity.ServiceMessages.Write.Special;\nusing var writer = GetService\u003cITeamCityWriter\u003e();\n```\nThis sample opens a block _My Tests_ and reports about two tests:\n``` CSharp\n// Adds a namespace to use ITeamCityWriter\nusing JetBrains.TeamCity.ServiceMessages.Write.Special;\n\nusing var writer = GetService\u003cITeamCityWriter\u003e();\nusing (var tests = writer.OpenBlock(\"My Tests\"))\n{\n    using (var test = tests.OpenTest(\"Test1\"))\n    {\n        test.WriteStdOutput(\"Hello\");\n        test.WriteImage(\"TestsResults/Test1Screenshot.jpg\", \"Screenshot\");\n        test.WriteDuration(TimeSpan.FromMilliseconds(10));\n    }\n\n    using (var test = tests.OpenTest(\"Test2\"))\n    {\n        test.WriteIgnored(\"Some reason\");\n    }\n}\n```\nFor more information on TeamCity Service Messages, see [this](https://www.jetbrains.com/help/teamcity/service-messages.html) page.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevteam%2Fcsharp-interactive","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdevteam%2Fcsharp-interactive","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevteam%2Fcsharp-interactive/lists"}