Skip to content

Commit

Permalink
Add usage examples
Browse files Browse the repository at this point in the history
  • Loading branch information
NikolayPianikov committed Sep 16, 2024
1 parent adfb4d1 commit ec2a4e2
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 20 deletions.
20 changes: 10 additions & 10 deletions CSharpInteractive.Tests/README_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,10 @@ Besides that, it is possible to get an instance of [System.IServiceProvider](htt
``` CSharp
public void Run()
{
var serviceProvider =
var serviceProvider =
GetService<IServiceCollection>()
.AddTransient<MyTask>()
.BuildServiceProvider();
.AddTransient<MyTask>()
.BuildServiceProvider();

var myTask = serviceProvider.GetRequiredService<MyTask>();
var exitCode = myTask.Run();
Expand Down Expand Up @@ -451,7 +451,7 @@ var result = dockerRun
result.Errors.Any(message => message.State == BuildMessageState.StdError).ShouldBeFalse();
result.ExitCode.ShouldBe(0);

string ToAbsoluteLinuxPath(string path) =>
string ToAbsoluteLinuxPath(string path) =>
"/" + path.Replace(":", "").Replace('\\', '/');
```

Expand Down Expand Up @@ -614,10 +614,10 @@ result.ExitCode.ShouldBe(0);

// Creates a NuGet package of version 1.2.3 for the project, running a command like: "dotnet pack /p:version=1.2.3" from the directory "MyLib"
result = new DotNetPack()
.WithWorkingDirectory("MyLib")
.AddProps(("version", "1.2.3"))
.Build()
.EnsureSuccess();
.WithWorkingDirectory("MyLib")
.AddProps(("version", "1.2.3"))
.Build()
.EnsureSuccess();

result.ExitCode.ShouldBe(0);
```
Expand Down Expand Up @@ -775,7 +775,7 @@ var testUnderDotCover = test.Customize(cmd =>
+ $"--dcOutput={dotCoverSnapshot}"
+ "--dcFilters=+:module=TeamCity.CSharpInteractive.HostApi;+:module=dotnet-csi"
+ "--dcAttributeFilters=System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage");

// Runs tests under dotCover via a command like: "dotnet dotcover test ..."
var result = testUnderDotCover
.Build()
Expand Down Expand Up @@ -805,7 +805,7 @@ using HostApi;

var projectDir = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()[..4]);
Directory.CreateDirectory(projectDir);

// Creates a local tool manifest
new DotNetNew("tool-manifest")
.WithWorkingDirectory(projectDir)
Expand Down
1 change: 1 addition & 0 deletions CSharpInteractive.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=decoherence/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=dependencyinjection/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Enumerables/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=immutype/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=initializers/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=inversionofcontrol/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=multithreading/@EntryIndexedValue">True</s:Boolean>
Expand Down
28 changes: 18 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,14 @@ The created project contains 2 entry points:
| 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 |
| 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 |

## Usage examples

- [Build project example](https://github.com/DevTeam/csharp-interactive/tree/master/Samples/MySampleLib)
- [CSharp Interactive build project](https://github.com/DevTeam/csharp-interactive/tree/master/Build)
- [Pure.DI build project](https://github.com/DevTeam/Pure.DI/tree/master/build)
- [Immutype build project](https://github.com/DevTeam/Immutype/tree/master/Build)
- [Comparison with Cake and Nuke](https://github.com/DevTeam/ci-cd)

## API

- Output, logging and tracing
Expand Down Expand Up @@ -293,10 +301,10 @@ Besides that, it is possible to get an instance of [System.IServiceProvider](htt
``` CSharp
public void Run()
{
var serviceProvider =
var serviceProvider =
GetService<IServiceCollection>()
.AddTransient<MyTask>()
.BuildServiceProvider();
.AddTransient<MyTask>()
.BuildServiceProvider();
var myTask = serviceProvider.GetRequiredService<MyTask>();
var exitCode = myTask.Run();
Expand Down Expand Up @@ -562,7 +570,7 @@ var result = dockerRun
result.Errors.Any(message => message.State == BuildMessageState.StdError).ShouldBeFalse();
result.ExitCode.ShouldBe(0);
string ToAbsoluteLinuxPath(string path) =>
string ToAbsoluteLinuxPath(string path) =>
"/" + path.Replace(":", "").Replace('\\', '/');
```
Expand Down Expand Up @@ -725,10 +733,10 @@ result.ExitCode.ShouldBe(0);
// Creates a NuGet package of version 1.2.3 for the project, running a command like: "dotnet pack /p:version=1.2.3" from the directory "MyLib"
result = new DotNetPack()
.WithWorkingDirectory("MyLib")
.AddProps(("version", "1.2.3"))
.Build()
.EnsureSuccess();
.WithWorkingDirectory("MyLib")
.AddProps(("version", "1.2.3"))
.Build()
.EnsureSuccess();
result.ExitCode.ShouldBe(0);
```
Expand Down Expand Up @@ -886,7 +894,7 @@ var testUnderDotCover = test.Customize(cmd =>
+ $"--dcOutput={dotCoverSnapshot}"
+ "--dcFilters=+:module=TeamCity.CSharpInteractive.HostApi;+:module=dotnet-csi"
+ "--dcAttributeFilters=System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage");
// Runs tests under dotCover via a command like: "dotnet dotcover test ..."
var result = testUnderDotCover
.Build()
Expand Down Expand Up @@ -916,7 +924,7 @@ using HostApi;
var projectDir = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()[..4]);
Directory.CreateDirectory(projectDir);
// Creates a local tool manifest
new DotNetNew("tool-manifest")
.WithWorkingDirectory(projectDir)
Expand Down
8 changes: 8 additions & 0 deletions README_BODY.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,11 @@ The created project contains 2 entry points:
| 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 |
| 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 |
| 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 |

## Usage examples

- [Build project example](https://github.com/DevTeam/csharp-interactive/tree/master/Samples/MySampleLib)
- [CSharp Interactive build project](https://github.com/DevTeam/csharp-interactive/tree/master/Build)
- [Pure.DI build project](https://github.com/DevTeam/Pure.DI/tree/master/build)
- [Immutype build project](https://github.com/DevTeam/Immutype/tree/master/Build)
- [Comparison with Cake and Nuke](https://github.com/DevTeam/ci-cd)

0 comments on commit ec2a4e2

Please sign in to comment.