Skip to content
Open
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: 13 additions & 6 deletions Rubjerg.Graphviz/GraphvizCommand.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
Expand Down Expand Up @@ -40,12 +41,18 @@ internal static string Rid
internal static readonly Lazy<string> _DotExePath = new Lazy<string>(() =>
{
// Depending on the method of deployment, there are several possible directories to look for dot
string[] possibleLocations = [
Path.Combine(AppContext.BaseDirectory, "runtimes", Rid, "native"),
Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
Path.GetDirectoryName(AppContext.BaseDirectory),
""
];
// The DOT_BINARY_PATH environment variable can be set to point to a specific location, which will be checked first.
var dotBinaryPath = Environment.GetEnvironmentVariable("DOT_BINARY_PATH");
var possibleLocations = new List<string>();
if (!string.IsNullOrEmpty(dotBinaryPath))
{
possibleLocations.Add(dotBinaryPath);
}
possibleLocations.Add(Path.Combine(AppContext.BaseDirectory, "runtimes", Rid, "native"));
possibleLocations.Add(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));
possibleLocations.Add(Path.GetDirectoryName(AppContext.BaseDirectory));
possibleLocations.Add("");

return possibleLocations.Where(d => d != null).Select(dir => Path.Combine(dir, "dot")).FirstOrDefault(File.Exists)
?? possibleLocations.Where(d => d != null).Select(dir => Path.Combine(dir, "dot.exe")).FirstOrDefault(File.Exists)
?? throw new InvalidOperationException("Could not find path to dot binary in any of: " + string.Join(", ", possibleLocations));
Expand Down
Loading