Skip to content

Commit 3c9a688

Browse files
Update README.md
1 parent 71c8b7f commit 3c9a688

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+420
-709
lines changed

CSharpInteractive.Tests/README_TEMPLATE.md

Lines changed: 162 additions & 161 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,36 @@
11

2-
## Usage Scenarios
2+
## API
33

4-
- Global state
5-
- [Using Args](#using-args)
6-
- [Using Props](#using-props)
7-
- [Using the Host property](#using-the-host-property)
8-
- [Get services](#get-services)
9-
- [Service collection](#service-collection)
10-
- Logging
4+
- Output, logging and tracing
115
- [Write a line to a build log](#write-a-line-to-a-build-log)
126
- [Write a line highlighted with "Header" color to a build log](#write-a-line-highlighted-with-"header"-color-to-a-build-log)
137
- [Write an empty line to a build log](#write-an-empty-line-to-a-build-log)
148
- [Log an error to a build log](#log-an-error-to-a-build-log)
159
- [Log a warning to a build log](#log-a-warning-to-a-build-log)
1610
- [Log information to a build log](#log-information-to-a-build-log)
1711
- [Log trace information to a build log](#log-trace-information-to-a-build-log)
18-
- Command Line API
12+
- Arguments and parameters
13+
- [Using Args](#using-args)
14+
- [Using Props](#using-props)
15+
- Microsoft DI
16+
- [Using the Host property](#using-the-host-property)
17+
- [Get services](#get-services)
18+
- [Service collection](#service-collection)
19+
- NuGet
20+
- [Restore NuGet a package of newest version](#restore-nuget-a-package-of-newest-version)
21+
- [Restore a NuGet package by a version range for the specified .NET and path](#restore-a-nuget-package-by-a-version-range-for-the-specified-.net-and-path)
22+
- Command Line
1923
- [Build command lines](#build-command-lines)
2024
- [Run a command line](#run-a-command-line)
2125
- [Run a command line asynchronously](#run-a-command-line-asynchronously)
2226
- [Run and process output](#run-and-process-output)
2327
- [Run asynchronously in parallel](#run-asynchronously-in-parallel)
2428
- [Cancellation of asynchronous run](#cancellation-of-asynchronous-run)
2529
- [Run timeout](#run-timeout)
26-
- Docker API
30+
- Docker CLI
2731
- [Build a project in a docker container](#build-a-project-in-a-docker-container)
2832
- [Running in docker](#running-in-docker)
29-
- .NET build API
33+
- .NET CLI
3034
- [Build a project](#build-a-project)
3135
- [Build a project using MSBuild](#build-a-project-using-msbuild)
3236
- [Clean a project](#clean-a-project)
@@ -41,12 +45,79 @@
4145
- [Test a project using the MSBuild VSTest target](#test-a-project-using-the-msbuild-vstest-target)
4246
- [Test an assembly](#test-an-assembly)
4347
- [Shuts down build servers](#shuts-down-build-servers)
44-
- NuGet API
45-
- [Restore NuGet a package of newest version](#restore-nuget-a-package-of-newest-version)
46-
- [Restore a NuGet package by a version range for the specified .NET and path](#restore-a-nuget-package-by-a-version-range-for-the-specified-.net-and-path)
47-
- TeamCity Service Messages API
48+
- TeamCity API
4849
- [TeamCity integration via service messages](#teamcity-integration-via-service-messages)
4950

51+
### Write a line to a build log
52+
53+
54+
55+
``` CSharp
56+
WriteLine("Hello");
57+
```
58+
59+
60+
61+
### Write an empty line to a build log
62+
63+
64+
65+
``` CSharp
66+
WriteLine();
67+
```
68+
69+
70+
71+
### Write a line highlighted with "Header" color to a build log
72+
73+
74+
75+
``` CSharp
76+
WriteLine("Hello", Header);
77+
```
78+
79+
80+
81+
### Log an error to a build log
82+
83+
84+
85+
``` CSharp
86+
Error("Error info", "Error identifier");
87+
```
88+
89+
90+
91+
### Log a warning to a build log
92+
93+
94+
95+
``` CSharp
96+
Warning("Warning info");
97+
```
98+
99+
100+
101+
### Log information to a build log
102+
103+
104+
105+
``` CSharp
106+
Info("Some info");
107+
```
108+
109+
110+
111+
### Log trace information to a build log
112+
113+
114+
115+
``` CSharp
116+
Trace("Some trace info");
117+
```
118+
119+
120+
50121
### Using Args
51122

52123
_Args_ have got from the script arguments.
@@ -133,72 +204,38 @@ private class MyTask(ICommandLineRunner runner)
133204

134205

135206

136-
### Write a line to a build log
137-
138-
139-
140-
``` CSharp
141-
WriteLine("Hello");
142-
```
143-
144-
145-
146-
### Write an empty line to a build log
147-
148-
149-
150-
``` CSharp
151-
WriteLine();
152-
```
153-
154-
155-
156-
### Write a line highlighted with "Header" color to a build log
157-
158-
159-
160-
``` CSharp
161-
WriteLine("Hello", Header);
162-
```
163-
164-
165-
166-
### Log an error to a build log
207+
### Restore NuGet a package of newest version
167208

168209

169210

170211
``` CSharp
171-
Error("Error info", "Error identifier");
172-
```
173-
174-
175-
176-
### Log a warning to a build log
177-
178-
212+
// Adds the namespace "HostApi" to use INuGet
213+
using HostApi;
179214

180-
``` CSharp
181-
Warning("Warning info");
215+
IEnumerable<NuGetPackage> packages = GetService<INuGet>()
216+
.Restore(new NuGetRestoreSettings("IoC.Container").WithVersionRange(VersionRange.All));
182217
```
183218

184219

185220

186-
### Log information to a build log
221+
### Restore a NuGet package by a version range for the specified .NET and path
187222

188223

189224

190225
``` CSharp
191-
Info("Some info");
192-
```
193-
194-
195-
196-
### Log trace information to a build log
226+
// Adds the namespace "HostApi" to use INuGet
227+
using HostApi;
197228

229+
var packagesPath = Path.Combine(
230+
Path.GetTempPath(),
231+
Guid.NewGuid().ToString()[..4]);
198232

233+
var settings = new NuGetRestoreSettings("IoC.Container")
234+
.WithVersionRange(VersionRange.Parse("[1.3, 1.3.8)"))
235+
.WithTargetFrameworkMoniker("net5.0")
236+
.WithPackagesPath(packagesPath);
199237

200-
``` CSharp
201-
Trace("Some trace info");
238+
IEnumerable<NuGetPackage> packages = GetService<INuGet>().Restore(settings);
202239
```
203240

204241

@@ -380,6 +417,66 @@ exitCode.HasValue.ShouldBeFalse();
380417

381418

382419

420+
### Build a project in a docker container
421+
422+
423+
424+
``` CSharp
425+
// Adds the namespace "HostApi" to use .NET build API and Docker API
426+
using HostApi;
427+
428+
// Creates a base docker command line
429+
var dockerRun = new DockerRun()
430+
.WithAutoRemove(true)
431+
.WithInteractive(true)
432+
.WithImage("mcr.microsoft.com/dotnet/sdk")
433+
.WithPlatform("linux")
434+
.WithContainerWorkingDirectory("/MyProjects")
435+
.AddVolumes((ToAbsoluteLinuxPath(Environment.CurrentDirectory), "/MyProjects"));
436+
437+
438+
// Creates a new library project in a docker container
439+
dockerRun
440+
.WithCommandLine(new DotNetCustom("new", "classlib", "-n", "MyLib", "--force"))
441+
.Run()
442+
.EnsureSuccess();
443+
444+
// Builds the library project in a docker container
445+
var result = dockerRun
446+
.WithCommandLine(new DotNetBuild().WithProject("MyLib/MyLib.csproj"))
447+
.Build()
448+
.EnsureSuccess();
449+
450+
// The "result" variable provides details about a build
451+
result.Errors.Any(message => message.State == BuildMessageState.StdError).ShouldBeFalse();
452+
result.ExitCode.ShouldBe(0);
453+
454+
string ToAbsoluteLinuxPath(string path) =>
455+
"/" + path.Replace(":", "").Replace('\\', '/');
456+
```
457+
458+
459+
460+
### Running in docker
461+
462+
463+
464+
``` CSharp
465+
// Adds the namespace "HostApi" to use Command Line API and Docker API
466+
using HostApi;
467+
468+
// Creates some command line to run in a docker container
469+
var cmd = new CommandLine("whoami");
470+
471+
// Runs the command line in a docker container
472+
var result = new DockerRun(cmd, "mcr.microsoft.com/dotnet/sdk")
473+
.WithAutoRemove(true)
474+
.Run()
475+
.EnsureSuccess();
476+
```
477+
478+
479+
383480
### Build a project
384481

385482

@@ -812,102 +909,6 @@ new DotNetBuildServerShutdown()
812909

813910

814911

815-
### Restore NuGet a package of newest version
816-
817-
818-
819-
``` CSharp
820-
// Adds the namespace "HostApi" to use INuGet
821-
using HostApi;
822-
823-
IEnumerable<NuGetPackage> packages = GetService<INuGet>()
824-
.Restore(new NuGetRestoreSettings("IoC.Container").WithVersionRange(VersionRange.All));
825-
```
826-
827-
828-
829-
### Restore a NuGet package by a version range for the specified .NET and path
830-
831-
832-
833-
``` CSharp
834-
// Adds the namespace "HostApi" to use INuGet
835-
using HostApi;
836-
837-
var packagesPath = Path.Combine(
838-
Path.GetTempPath(),
839-
Guid.NewGuid().ToString()[..4]);
840-
841-
var settings = new NuGetRestoreSettings("IoC.Container")
842-
.WithVersionRange(VersionRange.Parse("[1.3, 1.3.8)"))
843-
.WithTargetFrameworkMoniker("net5.0")
844-
.WithPackagesPath(packagesPath);
845-
846-
IEnumerable<NuGetPackage> packages = GetService<INuGet>().Restore(settings);
847-
```
848-
849-
850-
851-
### Build a project in a docker container
852-
853-
854-
855-
``` CSharp
856-
// Adds the namespace "HostApi" to use .NET build API and Docker API
857-
using HostApi;
858-
859-
// Creates a base docker command line
860-
var dockerRun = new DockerRun()
861-
.WithAutoRemove(true)
862-
.WithInteractive(true)
863-
.WithImage("mcr.microsoft.com/dotnet/sdk")
864-
.WithPlatform("linux")
865-
.WithContainerWorkingDirectory("/MyProjects")
866-
.AddVolumes((ToAbsoluteLinuxPath(Environment.CurrentDirectory), "/MyProjects"));
867-
868-
869-
// Creates a new library project in a docker container
870-
dockerRun
871-
.WithCommandLine(new DotNetCustom("new", "classlib", "-n", "MyLib", "--force"))
872-
.Run()
873-
.EnsureSuccess();
874-
875-
// Builds the library project in a docker container
876-
var result = dockerRun
877-
.WithCommandLine(new DotNetBuild().WithProject("MyLib/MyLib.csproj"))
878-
.Build()
879-
.EnsureSuccess();
880-
881-
// The "result" variable provides details about a build
882-
result.Errors.Any(message => message.State == BuildMessageState.StdError).ShouldBeFalse();
883-
result.ExitCode.ShouldBe(0);
884-
885-
string ToAbsoluteLinuxPath(string path) =>
886-
"/" + path.Replace(":", "").Replace('\\', '/');
887-
```
888-
889-
890-
891-
### Running in docker
892-
893-
894-
895-
``` CSharp
896-
// Adds the namespace "HostApi" to use Command Line API and Docker API
897-
using HostApi;
898-
899-
// Creates some command line to run in a docker container
900-
var cmd = new CommandLine("whoami");
901-
902-
// Runs the command line in a docker container
903-
var result = new DockerRun(cmd, "mcr.microsoft.com/dotnet/sdk")
904-
.WithAutoRemove(true)
905-
.Run()
906-
.EnsureSuccess();
907-
```
908-
909-
910-
911912
### TeamCity integration via service messages
912913

913914
For 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:

0 commit comments

Comments
 (0)