From ec2a4e27e856f038037d22e3398d55167ba57b09 Mon Sep 17 00:00:00 2001 From: Nikolay Pianikov Date: Mon, 16 Sep 2024 17:42:12 +0300 Subject: [PATCH] Add usage examples --- CSharpInteractive.Tests/README_TEMPLATE.md | 20 ++++++++-------- CSharpInteractive.sln.DotSettings | 1 + README.md | 28 ++++++++++++++-------- README_BODY.md | 8 +++++++ 4 files changed, 37 insertions(+), 20 deletions(-) diff --git a/CSharpInteractive.Tests/README_TEMPLATE.md b/CSharpInteractive.Tests/README_TEMPLATE.md index 4b8b56cd..e3f72789 100644 --- a/CSharpInteractive.Tests/README_TEMPLATE.md +++ b/CSharpInteractive.Tests/README_TEMPLATE.md @@ -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() - .AddTransient() - .BuildServiceProvider(); + .AddTransient() + .BuildServiceProvider(); var myTask = serviceProvider.GetRequiredService(); var exitCode = myTask.Run(); @@ -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('\\', '/'); ``` @@ -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); ``` @@ -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() @@ -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) diff --git a/CSharpInteractive.sln.DotSettings b/CSharpInteractive.sln.DotSettings index 67afbc9b..4693855f 100644 --- a/CSharpInteractive.sln.DotSettings +++ b/CSharpInteractive.sln.DotSettings @@ -303,6 +303,7 @@ True True True + True True True True diff --git a/README.md b/README.md index 215d468b..0d9fec10 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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() - .AddTransient() - .BuildServiceProvider(); + .AddTransient() + .BuildServiceProvider(); var myTask = serviceProvider.GetRequiredService(); var exitCode = myTask.Run(); @@ -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('\\', '/'); ``` @@ -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); ``` @@ -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() @@ -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) diff --git a/README_BODY.md b/README_BODY.md index d23239e1..55fa95ec 100644 --- a/README_BODY.md +++ b/README_BODY.md @@ -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)