Skip to content

Commit 7265c14

Browse files
authored
Resolve assembly location for SingleFile (#1686)
1 parent 0321a31 commit 7265c14

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/BenchmarkDotNet/Running/BuildPartition.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
using System;
2+
using System.IO;
3+
using System.Reflection;
24
using BenchmarkDotNet.Characteristics;
35
using BenchmarkDotNet.Configs;
46
using BenchmarkDotNet.Environments;
@@ -34,7 +36,7 @@ public BuildPartition(BenchmarkBuildInfo[] benchmarks, IResolver resolver)
3436

3537
public IResolver Resolver { get; }
3638

37-
public string AssemblyLocation => RepresentativeBenchmarkCase.Descriptor.Type.Assembly.Location;
39+
public string AssemblyLocation => GetResolvedAssemblyLocation(RepresentativeBenchmarkCase.Descriptor.Type.Assembly);
3840

3941
public string BuildConfiguration => RepresentativeBenchmarkCase.Job.ResolveValue(InfrastructureMode.BuildConfigurationCharacteristic, Resolver);
4042

@@ -60,5 +62,10 @@ public BuildPartition(BenchmarkBuildInfo[] benchmarks, IResolver resolver)
6062
public bool IsCustomBuildConfiguration => BuildConfiguration != InfrastructureMode.ReleaseConfigurationName;
6163

6264
public override string ToString() => RepresentativeBenchmarkCase.Job.DisplayInfo;
65+
66+
private static string GetResolvedAssemblyLocation(Assembly assembly) =>
67+
// in case of SingleFile, location.Length returns 0, so we use GetName() and
68+
// manually construct the path.
69+
assembly.Location.Length == 0 ? Path.Combine(AppContext.BaseDirectory, assembly.GetName().Name) : assembly.Location;
6370
}
64-
}
71+
}

src/BenchmarkDotNet/Toolchains/CsProj/CsProjGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public CsProjGenerator(string targetFrameworkMoniker, string cliPath, string pac
3535

3636
protected override string GetBuildArtifactsDirectoryPath(BuildPartition buildPartition, string programName)
3737
{
38-
string assemblyLocation = buildPartition.AssemblyLocation;
38+
string assemblyLocation = buildPartition.RepresentativeBenchmarkCase.Descriptor.Type.Assembly.Location;
3939

4040
//Assembles loaded from a stream will have an empty location (https://docs.microsoft.com/en-us/dotnet/api/system.reflection.assembly.location).
4141
string directoryName = assemblyLocation.IsEmpty() ?

0 commit comments

Comments
 (0)