11using System ;
2+ using System . Collections . Generic ;
23using System . Diagnostics ;
34using System . IO ;
45using System . Reflection ;
@@ -27,6 +28,9 @@ internal static string Rid
2728 Architecture . Arm64 => "arm64" ,
2829 Architecture . X86 => "x86" ,
2930 Architecture . Arm => "arm" ,
31+ // Cast allows compilation in .NET Standard 2.0/2.1.
32+ // (Architecture)5 is S390x, added in .NET 6.
33+ ( Architecture ) 5 => "s390x" ,
3034 _ => "unknown"
3135 } ;
3236
@@ -37,12 +41,18 @@ internal static string Rid
3741 internal static readonly Lazy < string > _DotExePath = new Lazy < string > ( ( ) =>
3842 {
3943 // Depending on the method of deployment, there are several possible directories to look for dot
40- string [ ] possibleLocations = [
41- Path . Combine ( AppContext . BaseDirectory , "runtimes" , Rid , "native" ) ,
42- Path . GetDirectoryName ( Assembly . GetExecutingAssembly ( ) . Location ) ,
43- Path . GetDirectoryName ( AppContext . BaseDirectory ) ,
44- ""
45- ] ;
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+
4656 return possibleLocations . Where ( d => d != null ) . Select ( dir => Path . Combine ( dir , "dot" ) ) . FirstOrDefault ( File . Exists )
4757 ?? possibleLocations . Where ( d => d != null ) . Select ( dir => Path . Combine ( dir , "dot.exe" ) ) . FirstOrDefault ( File . Exists )
4858 ?? throw new InvalidOperationException ( "Could not find path to dot binary in any of: " + string . Join ( ", " , possibleLocations ) ) ;
0 commit comments