Skip to content
This repository was archived by the owner on Jul 18, 2024. It is now read-only.

Commit 6bbc2e1

Browse files
Lots of minor fixes
1 parent c380e48 commit 6bbc2e1

File tree

17 files changed

+176
-80
lines changed

17 files changed

+176
-80
lines changed

.config/dotnet-tools.json

+1-8
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,11 @@
33
"isRoot": true,
44
"tools": {
55
"jetbrains.dotcover.globaltool": {
6-
"version": "2022.1.2",
6+
"version": "2023.2.5",
77
"commands": [
88
"dotnet-dotcover"
99
],
1010
"rollForward": false
11-
},
12-
"dotnet-csi": {
13-
"version": "1.0.7",
14-
"commands": [
15-
"dotnet-csi"
16-
],
17-
"rollForward": false
1811
}
1912
}
2013
}

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@
66
*.user
77
.teamcity/target/
88
.reports/
9+
.packages

Build/Program.cs

+38-13
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,8 @@
134134
.EnsureSuccess();
135135

136136
var dotCoverReportXml = Path.Combine(reportDir, "dotCover.xml");
137-
new DotNetCustom("dotCover", "report", $"--source={dotCoverSnapshot}", $"--output={dotCoverReportXml}", "--reportType=TeamCityXml").WithShortName("Generating the code coverage reports").Run().EnsureSuccess();
137+
new DotNetCustom("dotCover", "report", $"--source={dotCoverSnapshot}", $"--output={dotCoverReportXml}", "--reportType=TeamCityXml").WithShortName("Generating the code coverage reports")
138+
.Run().EnsureSuccess();
138139

139140
if (TryGetCoverage(dotCoverReportXml, out coveragePercentage))
140141
{
@@ -176,20 +177,22 @@
176177
var installTool = new DotNetCustom("tool", "install", toolPackageId, "-g", "--version", packageVersion.ToString(), "--add-source", Path.Combine(outputDir, "CSharpInteractive.Tool"))
177178
.WithShortName("Installing tool");
178179

179-
if (installTool.Run(output => WriteLine(output.Line)).ExitCode != 0)
180+
installTool.Run(output =>
180181
{
181-
Warning($"{installTool} failed.");
182-
}
182+
output.Handled = true;
183+
WriteLine(output.Line);
184+
}).EnsureSuccess(r => default);
183185

184186
new DotNetCustom("csi", "/?").WithShortName("Checking tool").Run().EnsureSuccess();
185187

186188
var uninstallTemplates = new DotNetCustom("new", "uninstall", templatesPackageId)
187189
.WithShortName("Uninstalling template");
188190

189-
if (uninstallTemplates.Run(output => WriteLine(output.Line)).ExitCode != 0)
191+
uninstallTemplates.Run(output =>
190192
{
191-
Warning($"{uninstallTemplates} failed.");
192-
}
193+
output.Handled = true;
194+
WriteLine(output.Line);
195+
}).EnsureSuccess(r => default);;
193196

194197
var installTemplates = new DotNetCustom("new", "install", $"{templatesPackageId}::{packageVersion.ToString()}", "--nuget-source", templateOutputDir)
195198
.WithShortName("Installing template");
@@ -204,10 +207,28 @@
204207
try
205208
{
206209
var sampleProjectDir = Path.Combine("Samples", "MySampleLib", "MySampleLib.Tests");
207-
new DotNetNew("build", $"--package-version={packageVersion}", "-T", framework, "--no-restore").WithWorkingDirectory(buildProjectDir).WithShortName($"Creating a new {sampleProjectName}").Run().EnsureSuccess();
208-
new DotNetBuild().WithProject(buildProjectDir).WithSources(defaultNuGetSource, Path.Combine(outputDir, "CSharpInteractive")).WithShortName($"Building the {sampleProjectName}").Build().EnsureSuccess();
209-
new DotNetRun().WithProject(buildProjectDir).WithNoBuild(true).WithWorkingDirectory(sampleProjectDir).WithShortName($"Running a build for the {sampleProjectName}").Run().EnsureSuccess();
210-
new DotNetCustom("csi", Path.Combine(buildProjectDir, "Program.csx")).WithWorkingDirectory(sampleProjectDir).WithShortName($"Running a build as a C# script for the {sampleProjectName}").Run().EnsureSuccess();
210+
new DotNetNew("build", $"--package-version={packageVersion}", "-T", framework, "--no-restore")
211+
.WithWorkingDirectory(buildProjectDir)
212+
.WithShortName($"Creating a new {sampleProjectName}")
213+
.Run().EnsureSuccess();
214+
215+
new DotNetBuild()
216+
.WithProject(buildProjectDir)
217+
.WithSources(defaultNuGetSource, Path.Combine(outputDir, "CSharpInteractive"))
218+
.WithShortName($"Building the {sampleProjectName}")
219+
.Build().EnsureSuccess();
220+
221+
new DotNetRun()
222+
.WithProject(buildProjectDir)
223+
.WithNoBuild(true)
224+
.WithWorkingDirectory(sampleProjectDir)
225+
.WithShortName($"Running a build for the {sampleProjectName}")
226+
.Run().EnsureSuccess();
227+
228+
new DotNetCustom("csi", Path.Combine(buildProjectDir, "Program.csx"))
229+
.WithWorkingDirectory(sampleProjectDir)
230+
.WithShortName($"Running a build as a C# script for the {sampleProjectName}")
231+
.Run().EnsureSuccess();
211232
}
212233
finally
213234
{
@@ -220,7 +241,9 @@
220241
var push = new DotNetNuGetPush().WithApiKey(apiKey).WithSources(defaultNuGetSource);
221242
foreach (var package in packages.Where(i => i.Publish))
222243
{
223-
push.WithPackage(package.Package).WithShortName($"Pushing {Path.GetFileName(package.Package)}").Build().EnsureSuccess();
244+
push.WithPackage(package.Package)
245+
.WithShortName($"Pushing {Path.GetFileName(package.Package)}")
246+
.Build().EnsureSuccess();
224247
}
225248
}
226249
else
@@ -232,7 +255,9 @@
232255
{
233256
var logicOp = integrationTests && dockerLinuxTests ? "|" : "&";
234257
var filter = $"Integration={integrationTests}{logicOp}Docker={dockerLinuxTests}";
235-
test.WithFilter(filter).Build().EnsureSuccess();
258+
test
259+
.WithFilter(filter)
260+
.Build().EnsureSuccess();
236261
}
237262

238263
WriteLine("To use the csi tool:", Color.Highlighted);

CSharpInteractive.HostApi/Internal/DotNet/DotNetCommandLineExtensions.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public static CommandLine AddMSBuildLoggers(this CommandLine cmd, IHost host, Do
5656
return settings.LoggersAreRequired
5757
? cmd
5858
.AddArgs("/noconsolelogger")
59-
.AddMSBuildArgs(("/l", $"TeamCity.MSBuild.Logger.TeamCityMSBuildLogger,{virtualContext.Resolve(settings.DotNetMSBuildLoggerDirectory)}/TeamCity.MSBuild.Logger.dll;TeamCity;plain"))
59+
.AddMSBuildArgs(("/l", $"TeamCity.MSBuild.Logger.TeamCityMSBuildLogger,{virtualContext.Resolve(settings.DotNetMSBuildLoggerDirectory)}/TeamCity.MSBuild.Logger.dll;TEAMCITY;PLAIN;NOSUMMARY"))
6060
.AddProps("-p",
6161
("VSTestLogger", TeamcityLoggerName),
6262
("VSTestTestAdapterPath", virtualContext.Resolve(settings.DotNetVSTestLoggerDirectory)),

CSharpInteractive.Templates/CSharpInteractive.Templates.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
<Title>C# script Templates</Title>
1616
<Description>$(Company) $(Title) $(Version) $(TargetFramework)</Description>
1717
<PackageType>Template</PackageType>
18+
<PackageReadmeFile>content/ConsoleApplication-CSharp/README.md</PackageReadmeFile>
1819
<SuppressDependenciesWhenPacking>True</SuppressDependenciesWhenPacking>
1920
</PropertyGroup>
2021

Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
using HostApi;
22

3-
// Builds a dotnet solution or project
4-
return new DotNetBuild().Build().ExitCode ?? 1;
3+
// Build a dotnet solution or project
4+
new DotNetBuild().Build().EnsureSuccess();

CSharpInteractive.Templates/content/ConsoleApplication-CSharp/Program.csx

+3-2
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@
1414
// To add an assembly reference:
1515
// #r "MyAssembly.dll"
1616

17-
// To include code from the file in the order in which it should be executed:
17+
// To include code from the file
18+
// in the order in which it should be executed:
1819
// #load "MyClass.cs"
1920

2021
// More information can be found on the page:
2122
// https://github.com/DevTeam/csharp-interactive
2223

23-
#load "Program.cs"
24+
#load "Program.cs"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
Install the C# script template [CSharpInteractive.Templates](https://www.nuget.org/packages/CSharpInteractive.Templates)
2+
3+
```shell
4+
dotnet new -i CSharpInteractive.Templates
5+
```
6+
7+
Create a console project "Build" containing a script from the template *__build__*
8+
9+
```shell
10+
dotnet new build -o ./Build
11+
```
12+
13+
This projects contains the script *__./Build/Program.csx__*. To run this script from the command line from the directory *__Build__*:
14+
15+
```shell
16+
dotnet csi Build
17+
```
18+
19+
To run as a .NET console application:
20+
21+
```shell
22+
dotnet run --project Build
23+
```

CSharpInteractive.Tests/README_TEMPLATE.md

+29-41
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,8 @@ public void Run()
123123

124124
private class MyTask(ICommandLineRunner runner)
125125
{
126-
127126
public int? Run() =>
128-
runner.Run(new CommandLine("whoami"));
127+
runner.Run(new CommandLine("whoami")).ExitCode;
129128
}
130129

131130
```
@@ -256,22 +255,18 @@ cmd = new CommandLine("cmd", "/c", "echo", "Hello")
256255
// Adds the namespace "HostApi" to use Command Line API
257256
using HostApi;
258257

259-
var exitCode = GetService<ICommandLineRunner>().Run(new CommandLine("cmd", "/c", "DIR"));
260-
exitCode.ShouldBe(0);
258+
GetService<ICommandLineRunner>().Run(new CommandLine("cmd", "/c", "DIR")).EnsureSuccess();
261259

262260
// or the same thing using the extension method
263-
exitCode = new CommandLine("cmd", "/c", "DIR").Run();
264-
exitCode.ShouldBe(0);
261+
new CommandLine("cmd", "/c", "DIR").Run().EnsureSuccess();
265262

266263
// using operator '+'
267264
var cmd = new CommandLine("cmd") + "/c" + "DIR";
268-
exitCode = cmd.Run();
269-
exitCode.ShouldBe(0);
265+
cmd.Run().EnsureSuccess();
270266

271267
// with environment variables
272268
cmd = new CommandLine("cmd") + "/c" + "DIR" + ("MyEnvVar", "Some Value");
273-
exitCode = cmd.Run();
274-
exitCode.ShouldBe(0);
269+
cmd.Run().EnsureSuccess();
275270
```
276271

277272

@@ -284,10 +279,10 @@ exitCode.ShouldBe(0);
284279
// Adds the namespace "HostApi" to use Command Line API
285280
using HostApi;
286281

287-
int? exitCode = await GetService<ICommandLineRunner>().RunAsync(new CommandLine("cmd", "/C", "DIR"));
282+
var task = await GetService<ICommandLineRunner>().RunAsync(new CommandLine("cmd", "/C", "DIR"));
288283

289284
// or the same thing using the extension method
290-
exitCode = await new CommandLine("cmd", "/c", "DIR").RunAsync();
285+
task = await new CommandLine("cmd", "/c", "DIR").RunAsync();
291286
```
292287

293288

@@ -303,7 +298,7 @@ using HostApi;
303298
var lines = new List<string>();
304299
int? exitCode = new CommandLine("cmd", "/c", "SET")
305300
.AddVars(("MyEnv", "MyVal"))
306-
.Run(output => lines.Add(output.Line));
301+
.Run(output => lines.Add(output.Line)).ExitCode;
307302

308303
lines.ShouldContain("MyEnv=MyVal");
309304
```
@@ -318,8 +313,8 @@ lines.ShouldContain("MyEnv=MyVal");
318313
// Adds the namespace "HostApi" to use Command Line API
319314
using HostApi;
320315

321-
Task<int?> task = new CommandLine("cmd", "/c", "DIR").RunAsync();
322-
int? exitCode = new CommandLine("cmd", "/c", "SET").Run();
316+
var task = new CommandLine("cmd", "/c", "DIR").RunAsync();
317+
var result = new CommandLine("cmd", "/c", "SET").Run();
323318
task.Wait();
324319
```
325320

@@ -334,7 +329,7 @@ The cancellation will kill a related process.
334329
using HostApi;
335330

336331
var cancellationTokenSource = new CancellationTokenSource();
337-
Task<int?> task = new CommandLine("cmd", "/c", "TIMEOUT", "/T", "120").RunAsync(default, cancellationTokenSource.Token);
332+
var task = new CommandLine("cmd", "/c", "TIMEOUT", "/T", "120").RunAsync(default, cancellationTokenSource.Token);
338333

339334
cancellationTokenSource.CancelAfter(TimeSpan.FromMilliseconds(100));
340335
task.IsCompleted.ShouldBeFalse();
@@ -350,7 +345,7 @@ If timeout expired a process will be killed.
350345
// Adds the namespace "HostApi" to use Command Line API
351346
using HostApi;
352347

353-
int? exitCode = new CommandLine("cmd", "/c", "TIMEOUT", "/T", "120").Run(default, TimeSpan.FromMilliseconds(1));
348+
int? exitCode = new CommandLine("cmd", "/c", "TIMEOUT", "/T", "120").Run(default, TimeSpan.FromMilliseconds(1)).ExitCode;
354349

355350
exitCode.HasValue.ShouldBeFalse();
356351
```
@@ -420,9 +415,10 @@ using HostApi;
420415

421416
// Gets the dotnet version, running a command like: "dotnet --version"
422417
NuGetVersion? version = default;
423-
var exitCode = new DotNetCustom("--version").Run(message => NuGetVersion.TryParse(message.Line, out version));
418+
var exitCode = new DotNetCustom("--version")
419+
.Run(message => NuGetVersion.TryParse(message.Line, out version))
420+
.EnsureSuccess();
424421

425-
exitCode.ShouldBe(0);
426422
version.ShouldNotBeNull();
427423
```
428424

@@ -569,17 +565,16 @@ result.Tests.Count(test => test.State == TestState.Finished).ShouldBe(1);
569565
using HostApi;
570566

571567
// Creates a new test project, running a command like: "dotnet new mstest -n MyTests --force"
572-
var exitCode = new DotNetNew("mstest", "-n", "MyTests", "--force").Run();
573-
exitCode.ShouldBe(0);
568+
new DotNetNew("mstest", "-n", "MyTests", "--force")
569+
.Run().EnsureSuccess();
574570

575571
// Creates the tool manifest and installs the dotCover tool locally
576572
// It is better to run the following 2 commands manually
577573
// and commit these changes to a source control
578-
exitCode = new DotNetNew("tool-manifest").Run();
579-
exitCode.ShouldBe(0);
574+
new DotNetNew("tool-manifest").Run().EnsureSuccess();
580575

581-
exitCode = new DotNetCustom("tool", "install", "--local", "JetBrains.dotCover.GlobalTool").Run();
582-
exitCode.ShouldBe(0);
576+
new DotNetCustom("tool", "install", "--local", "JetBrains.dotCover.GlobalTool")
577+
.Run().EnsureSuccess();
583578

584579
// Creates a test command
585580
var test = new DotNetTest().WithProject("MyTests");
@@ -605,8 +600,8 @@ result.ExitCode.ShouldBe(0);
605600
result.Tests.Count(i => i.State == TestState.Finished).ShouldBe(1);
606601

607602
// Generates a HTML code coverage report.
608-
exitCode = new DotNetCustom("dotCover", "report", $"--source={dotCoverSnapshot}", $"--output={dotCoverReport}", "--reportType=HTML").Run();
609-
exitCode.ShouldBe(0);
603+
new DotNetCustom("dotCover", "report", $"--source={dotCoverSnapshot}", $"--output={dotCoverReport}", "--reportType=HTML")
604+
.Run().EnsureSuccess();
610605

611606
// Check for a dotCover report
612607
File.Exists(dotCoverReport).ShouldBeTrue();
@@ -626,12 +621,10 @@ var projectDir = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()[..4]
626621
Directory.CreateDirectory(projectDir);
627622

628623
// Creates a local tool manifest
629-
var exitCode = new DotNetNew("tool-manifest").WithWorkingDirectory(projectDir).Run();
630-
exitCode.ShouldBe(0);
624+
new DotNetNew("tool-manifest").WithWorkingDirectory(projectDir).Run().EnsureSuccess();
631625

632626
// Restore local tools
633-
exitCode = new DotNetToolRestore().WithWorkingDirectory(projectDir).Run();
634-
exitCode.ShouldBe(0);
627+
new DotNetToolRestore().WithWorkingDirectory(projectDir).Run().EnsureSuccess();
635628
```
636629

637630

@@ -703,9 +696,7 @@ result.ExitCode.ShouldBe(0);
703696
using HostApi;
704697

705698
// Shuts down all build servers that are started from dotnet.
706-
var exitCode = new DotNetBuildServerShutdown().Run();
707-
708-
exitCode.ShouldBe(0);
699+
new DotNetBuildServerShutdown().Run().EnsureSuccess();
709700
```
710701

711702

@@ -764,11 +755,9 @@ var dockerRun = new DockerRun()
764755

765756

766757
// Creates a new library project in a docker container
767-
var exitCode = dockerRun
758+
dockerRun
768759
.WithCommandLine(new DotNetCustom("new", "classlib", "-n", "MyLib", "--force"))
769-
.Run();
770-
771-
exitCode.ShouldBe(0);
760+
.Run().EnsureSuccess();
772761

773762
// Builds the library project in a docker container
774763
var result = dockerRun
@@ -799,9 +788,8 @@ var cmd = new CommandLine("whoami");
799788
// Runs the command line in a docker container
800789
var result = new DockerRun(cmd, "mcr.microsoft.com/dotnet/sdk")
801790
.WithAutoRemove(true)
802-
.Run();
803-
804-
result.ShouldBe(0);
791+
.Run()
792+
.EnsureSuccess();
805793
```
806794

807795

CSharpInteractive.sln.DotSettings

+1
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@
305305
<s:Boolean x:Key="/Default/UserDictionary/Words/=Nikolay/@EntryIndexedValue">True</s:Boolean>
306306
<s:Boolean x:Key="/Default/UserDictionary/Words/=Ninject/@EntryIndexedValue">True</s:Boolean>
307307
<s:Boolean x:Key="/Default/UserDictionary/Words/=nologo/@EntryIndexedValue">True</s:Boolean>
308+
<s:Boolean x:Key="/Default/UserDictionary/Words/=nosummary/@EntryIndexedValue">True</s:Boolean>
308309
<s:Boolean x:Key="/Default/UserDictionary/Words/=nupkg/@EntryIndexedValue">True</s:Boolean>
309310
<s:Boolean x:Key="/Default/UserDictionary/Words/=Parallelize/@EntryIndexedValue">True</s:Boolean>
310311
<s:Boolean x:Key="/Default/UserDictionary/Words/=Pianikov/@EntryIndexedValue">True</s:Boolean>

CSharpInteractive/Core/Statistics.cs

-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ public IReadOnlyCollection<Text[]> Warnings
3535
}
3636
}
3737
}
38-
3938

4039
public TimeSpan TimeElapsed => _stopwatch.Elapsed;
4140

Directory.Build.props

-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
<Copyright>Copyright (C) $([System.DateTime]::Now.Year) $(Company)</Copyright>
1313
<RepositoryType>git</RepositoryType>
1414
<RepositoryUrl>https://github.com/DevTeam/csharp-interactive</RepositoryUrl>
15-
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
16-
<CompilerGeneratedFilesOutputPath>obj/Generated</CompilerGeneratedFilesOutputPath>
1715
<ImmutypeAPI>False</ImmutypeAPI>
1816
</PropertyGroup>
1917

0 commit comments

Comments
 (0)