Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

throw an exception when multiple benchmark projects with the same name are found #2143

Merged
merged 1 commit into from
Oct 7, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions src/BenchmarkDotNet/Toolchains/CsProj/CsProjGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,19 +154,24 @@ protected virtual FileInfo GetProjectFilePath(Type benchmarkTarget, ILogger logg
// important assumption! project's file name === output dll name
string projectName = benchmarkTarget.GetTypeInfo().Assembly.GetName().Name;

// I was afraid of using .GetFiles with some smart search pattern due to the fact that the method was designed for Windows
// and now .NET is cross platform so who knows if the pattern would be supported for other OSes
var possibleNames = new HashSet<string> { $"{projectName}.csproj", $"{projectName}.fsproj", $"{projectName}.vbproj" };
var projectFile = rootDirectory
.EnumerateFiles("*.*", SearchOption.AllDirectories)
.FirstOrDefault(file => possibleNames.Contains(file.Name));
var projectFiles = rootDirectory
.EnumerateFiles("*proj", SearchOption.AllDirectories)
.Where(file => possibleNames.Contains(file.Name))
.ToArray();

if (projectFile == default(FileInfo))
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 projectFile;
else 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.");
}

return projectFiles[0];
}

public override bool Equals(object obj) => obj is CsProjGenerator other && Equals(other);
Expand Down