BenchmarkDotNet
BenchmarkDotNet copied to clipboard
BenchmarkDotNet with non-[csproj,fsproj,vbproj] build environment?
I work in an equivalent make system that does not rely on csproj or other projects types as part of the build, but am interested in leveraging BenchmarkDotNet. With some hacking got to the point where the benchmark would execute, but hung up on logic that requires a proper project file to have been created (which doesn't/wont ever exist in the build environment).
Is this a hard requirement for BenchmarkDotNet?
Observed enforcement of this requirement (CsProjGenerator.cs):
[PublicAPI]
protected virtual FileInfo GetProjectFilePath(Type benchmarkTarget, ILogger logger)
{
if (!GetSolutionRootDirectory(out var rootDirectory) && !GetProjectRootDirectory(out rootDirectory))
{
logger.WriteLineError(
$"Unable to find .sln or .csproj file. Will use current directory {Directory.GetCurrentDirectory()} to search for project file. If you don't use .sln file on purpose it should not be a problem.");
rootDirectory = new DirectoryInfo(Directory.GetCurrentDirectory());
}
// 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));
if (projectFile == default(FileInfo))
{
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;
}