Skip to content

Commit 04975a5

Browse files
ratholeArthur Hillenaar
andauthored
Add DOT_BINARY_PATH environment variable support (#120)
Co-authored-by: Arthur Hillenaar <Arthur.Hillenaar@ibm.com>
1 parent a85d97a commit 04975a5

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

Rubjerg.Graphviz/GraphvizCommand.cs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.Diagnostics;
34
using System.IO;
45
using System.Reflection;
@@ -40,12 +41,18 @@ internal static string Rid
4041
internal static readonly Lazy<string> _DotExePath = new Lazy<string>(() =>
4142
{
4243
// Depending on the method of deployment, there are several possible directories to look for dot
43-
string[] possibleLocations = [
44-
Path.Combine(AppContext.BaseDirectory, "runtimes", Rid, "native"),
45-
Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
46-
Path.GetDirectoryName(AppContext.BaseDirectory),
47-
""
48-
];
44+
// The DOT_BINARY_PATH environment variable can be set to point to a specific location, which will be checked first.
45+
var dotBinaryPath = Environment.GetEnvironmentVariable("DOT_BINARY_PATH");
46+
var possibleLocations = new List<string>();
47+
if (!string.IsNullOrEmpty(dotBinaryPath))
48+
{
49+
possibleLocations.Add(dotBinaryPath);
50+
}
51+
possibleLocations.Add(Path.Combine(AppContext.BaseDirectory, "runtimes", Rid, "native"));
52+
possibleLocations.Add(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));
53+
possibleLocations.Add(Path.GetDirectoryName(AppContext.BaseDirectory));
54+
possibleLocations.Add("");
55+
4956
return possibleLocations.Where(d => d != null).Select(dir => Path.Combine(dir, "dot")).FirstOrDefault(File.Exists)
5057
?? possibleLocations.Where(d => d != null).Select(dir => Path.Combine(dir, "dot.exe")).FirstOrDefault(File.Exists)
5158
?? throw new InvalidOperationException("Could not find path to dot binary in any of: " + string.Join(", ", possibleLocations));

0 commit comments

Comments
 (0)