Skip to content

Commit 0f9bb33

Browse files
authored
Dont remove artifacts when build fails (#1567)
* don't remove the auto-generated files when the build fails * print a nice error with a link to troubleshooting guide * update the troubleshooting guide
1 parent 8de321c commit 0f9bb33

File tree

2 files changed

+32
-17
lines changed

2 files changed

+32
-17
lines changed

docs/articles/guides/troubleshooting.md

+21-14
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,33 @@ You need to be aware of the fact that to ensure process-level isolation Benchmar
77
How do you know that BenchmarkDotNet has failed to build the project? BDN is going to tell you about it. An example:
88

99
```log
10-
// ***** BenchmarkRunner: Start *****
11-
// ***** Building 1 exe(s) in Parallel: Start *****
12-
// msbuild /p:ConfigurationGroup=Release /p:UseSharedCompilation=false took 12,93s and exited with 1
13-
// ***** Done, took 00:00:15 (15.59 sec) *****
14-
// Found benchmarks:
15-
// Perf_Console.OpenStandardInput: Job-ZAFVFJ(Force=True, Toolchain=CoreFX, IterationCount=3, LaunchCount=1, WarmupCount=3)
16-
17-
// Build Exception: Microsoft (R) Build Engine version 15.9.8-preview+g0a5001fc4d for .NET Core
18-
Copyright (C) Microsoft Corporation. All rights reserved.
19-
20-
C:\Program Files\dotnet\sdk\2.2.100-preview2-009404\Microsoft.Common.CurrentVersion.targets(4176,5): warning MSB3026: Could not copy "C:\Projects\corefx/bin/obj/AnyOS.AnyCPU.Release/BenchmarksRunner/netstandard/BenchmarksRunner.exe" to "C:\Projects\corefx\bin/AnyOS.AnyCPU.Release/BenchmarksRunner/netstandard/BenchmarksRunner.exe". Beginning retry 1 in 1000ms. The process cannot access the file 'C:\Projects\corefx\bin\AnyOS.AnyCPU.Release\BenchmarksRunner\netstandard\BenchmarksRunner.exe' because it is being used by another process. [C:\Projects\corefx\src\Common\perf\BenchmarksRunner\BenchmarksRunner.csproj]
10+
// Validating benchmarks:
11+
// ***** BenchmarkRunner: Start *****
12+
// ***** Found 1 benchmark(s) in total *****
13+
// ***** Building 1 exe(s) in Parallel: Start *****
14+
// start dotnet restore /p:UseSharedCompilation=false /p:BuildInParallel=false /m:1 /p:Deterministic=true /p:Optimize=true in C:\Projects\BenchmarkDotNet\samples\BenchmarkDotNet.Samples\bin\Release\netcoreapp2.1\c6045772-d3c7-4dbe-ab37-4aca6dcb6ec4
15+
// command took 0.51s and exited with 1
16+
// ***** Done, took 00:00:00 (0.66 sec) *****
17+
// Found 1 benchmarks:
18+
// IntroBasic.Sleep: DefaultJob
19+
20+
// Build Error: Standard output:
21+
22+
Standard error:
23+
C:\Projects\BenchmarkDotNet\samples\BenchmarkDotNet.Samples\bin\Release\netcoreapp2.1\c6045772-d3c7-4dbe-ab37-4aca6dcb6ec4\BenchmarkDotNet.Autogenerated.csproj(36,1): error MSB4025: The project file could not be loaded. Unexpected end of file while parsing Comment has occurred. Line 36, position 1.
24+
25+
// BenchmarkDotNet has failed to build the auto-generated boilerplate code.
26+
// It can be found in C:\Projects\BenchmarkDotNet\samples\BenchmarkDotNet.Samples\bin\Release\netcoreapp2.1\c6045772-d3c7-4dbe-ab37-4aca6dcb6ec4
27+
// Please follow the troubleshooting guide: https://benchmarkdotnet.org/articles/guides/troubleshooting.html
2128
```
2229

2330
If the error message is not clear enough, you need to investigate it further.
2431

2532
How to troubleshoot the build process:
2633

27-
1. Configure BenchmarkDotNet to keep auto-generated benchmark files (they are being removed after benchmark is executed by default). You can do that by either passing `--keepFiles` console argument to `BenchmarkSwitcher` or by using `[KeepBenchmarkFiles]` attribute on the type which defines the benchmarks or by using `config.KeepBenchmarkFiles()` extension method.
28-
2. Run the benchmarks
29-
3. Go to the output folder, which typicaly is `bin\Release\$FrameworkMoniker` and search for the new folder with auto-generated files. The name of the folder is just Job's ID. So if you are using `--job short` the folder should be called "ShortRun". If you want to change the name, use `Job.WithId("$newID")` extension method.
34+
1. Run the benchmarks.
35+
2. Read the error message. If it does not contain the answer to your problem, please continue to the next step.
36+
3. Go to the build artifacts folder (path printed by BDN).
3037
4. The folder should contain:
3138
* a file with source code (ends with `.notcs` to make sure IDE don't include it in other projects by default)
3239
* a project file (`.csproj`)

src/BenchmarkDotNet/Running/BenchmarkRunnerClean.cs

+11-3
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,11 @@ private static Summary Run(BenchmarkRunInfo benchmarkRunInfo,
143143
var info = buildResults[benchmark];
144144
var buildResult = info.buildResult;
145145

146-
if (!config.Options.IsSet(ConfigOptions.KeepBenchmarkFiles))
147-
artifactsToCleanup.AddRange(buildResult.ArtifactsToCleanup);
148-
149146
if (buildResult.IsBuildSuccess)
150147
{
148+
if (!config.Options.IsSet(ConfigOptions.KeepBenchmarkFiles))
149+
artifactsToCleanup.AddRange(buildResult.ArtifactsToCleanup);
150+
151151
var report = RunCore(benchmark, info.benchmarkId, logger, resolver, buildResult);
152152
if (report.AllMeasurements.Any(m => m.Operations == 0))
153153
throw new InvalidOperationException("An iteration with 'Operations == 0' detected");
@@ -173,6 +173,14 @@ private static Summary Run(BenchmarkRunInfo benchmarkRunInfo,
173173
else if (buildResult.ErrorMessage != null)
174174
logger.WriteLineError($"// Build Error: {buildResult.ErrorMessage}");
175175

176+
if (!benchmark.Job.GetToolchain().IsInProcess)
177+
{
178+
logger.WriteLine();
179+
logger.WriteLineError("// BenchmarkDotNet has failed to build the auto-generated boilerplate code.");
180+
logger.WriteLineError($"// It can be found in {buildResult.ArtifactsPaths.BuildArtifactsDirectoryPath}");
181+
logger.WriteLineError("// Please follow the troubleshooting guide: https://benchmarkdotnet.org/articles/guides/troubleshooting.html");
182+
}
183+
176184
if (config.Options.IsSet(ConfigOptions.StopOnFirstError))
177185
break;
178186
}

0 commit comments

Comments
 (0)