From 94aa84c992821d2c8c51c12c9beacac8cbf9c984 Mon Sep 17 00:00:00 2001 From: Ian Qvist Date: Thu, 2 Jan 2025 16:44:20 +0100 Subject: [PATCH] Make ProjectLocator fall back to other locators if enabled --- src/BenchmarkDotNet/Locators/ProjectLocator.cs | 6 +++--- src/BenchmarkDotNet/Toolchains/CsProj/CsProjGenerator.cs | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/BenchmarkDotNet/Locators/ProjectLocator.cs b/src/BenchmarkDotNet/Locators/ProjectLocator.cs index 5467d3ff25..597b589977 100644 --- a/src/BenchmarkDotNet/Locators/ProjectLocator.cs +++ b/src/BenchmarkDotNet/Locators/ProjectLocator.cs @@ -26,10 +26,10 @@ public FileInfo Locate(DirectoryInfo rootDirectory, Type type) if (projectFiles.Length == 0) { - throw new NotSupportedException( - $"Unable to find {projectName} in {rootDirectory.FullName} and its subfolders. Most probably the name of output exe is different than the name of the .(c/f)sproj"); + return null; } - else if (projectFiles.Length > 1) + + if (projectFiles.Length > 1) { throw new NotSupportedException( $"Found more than one matching project file for {projectName} in {rootDirectory.FullName} and its subfolders: {string.Join(",", projectFiles.Select(pf => $"'{pf.FullName}'"))}. Benchmark project names needs to be unique."); diff --git a/src/BenchmarkDotNet/Toolchains/CsProj/CsProjGenerator.cs b/src/BenchmarkDotNet/Toolchains/CsProj/CsProjGenerator.cs index c2b3976bed..5d178ce9f0 100644 --- a/src/BenchmarkDotNet/Toolchains/CsProj/CsProjGenerator.cs +++ b/src/BenchmarkDotNet/Toolchains/CsProj/CsProjGenerator.cs @@ -266,6 +266,9 @@ protected virtual FileInfo GetProjectFilePath(BenchmarkCase benchmark, ILogger l var path = locator.Locate(rootDirectory, benchmarkTarget); + if (path == null) + continue; + if (path.Exists) return path;