From 886886d24a67d7d7c668c0b720960dca90649492 Mon Sep 17 00:00:00 2001 From: agracio Date: Thu, 28 Nov 2024 22:24:27 +0000 Subject: [PATCH] refactoring coreclrembedding.cs --- .../Edge.js/dotnetcore/coreclrembedding.cs | 60 +++++++++---------- 1 file changed, 27 insertions(+), 33 deletions(-) diff --git a/src/double/Edge.js/dotnetcore/coreclrembedding.cs b/src/double/Edge.js/dotnetcore/coreclrembedding.cs index 5c149582..c3ac81c7 100644 --- a/src/double/Edge.js/dotnetcore/coreclrembedding.cs +++ b/src/double/Edge.js/dotnetcore/coreclrembedding.cs @@ -249,8 +249,6 @@ private void AddDependencies(DependencyContext dependencyContext, bool standalon AddCompileDependencies(dependencyContext, standalone); - var runtimePath = Path.GetDirectoryName(RuntimeEnvironment.RuntimePath); - foreach (RuntimeLibrary runtimeLibrary in dependencyContext.RuntimeLibraries) { DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Processing runtime dependency {1} {0}", runtimeLibrary.Name, runtimeLibrary.Type); @@ -268,8 +266,6 @@ private void AddDependencies(DependencyContext dependencyContext, bool standalon if (_libraries.ContainsKey(runtimeLibrary.Name) && CompileAssemblies.ContainsKey(runtimeLibrary.Name)) { DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Already present in the runtime assemblies list, skipping"); - AddNativeAssemblies(dependencyContext, runtimeLibrary); - AddSupplementaryRuntime(runtimeLibrary); continue; } @@ -412,7 +408,7 @@ private void AddDependencyFromRuntime(RuntimeLibrary runtimeLibrary) if (CompileAssemblies.ContainsKey(runtimeLibrary.Name) && _libraries.ContainsKey(runtimeLibrary.Name)) return; var runtimePath = Path.GetDirectoryName(RuntimeEnvironment.RuntimePath); - DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Processing dependency {1} {0} using runtime path {2}", runtimeLibrary.Name, runtimeLibrary.Type, runtimePath); + DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Processing runtime dependency {1} {0} using runtime path {2}", runtimeLibrary.Name, runtimeLibrary.Type, runtimePath); if (string.IsNullOrEmpty(runtimePath)) { DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - runtime path could not be resolved, skipping"); @@ -420,20 +416,7 @@ private void AddDependencyFromRuntime(RuntimeLibrary runtimeLibrary) } var asset = runtimeLibrary.Name; - if (!asset.EndsWith(".dll") && !asset.EndsWith(".sni")) - { - asset += ".dll"; - } - - if (asset == "runtime.native.System.dll") - { - asset = "System.dll"; - } - - if (asset == "NETStandard.Library.dll") - { - asset = "netstandard.dll"; - } + asset = ReplaceAssetName(asset); var assemblyPath = Path.Combine(runtimePath, Path.GetFileName(asset)); if (File.Exists(assemblyPath)) @@ -441,12 +424,12 @@ private void AddDependencyFromRuntime(RuntimeLibrary runtimeLibrary) CompileAssemblies.TryAdd(runtimeLibrary.Name, assemblyPath); _libraries.TryAdd(runtimeLibrary.Name, assemblyPath); - DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Added dependency {1} from {0}", assemblyPath, runtimeLibrary.Name); + DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Added runtime dependency {1} from {0}", assemblyPath, runtimeLibrary.Name); AddSupplementaryRuntime(runtimeLibrary); } else { - DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Could not add dependency {0}", assemblyPath); + DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Could not runtime add dependency {0}", assemblyPath); } } @@ -454,18 +437,10 @@ private void AddDependencyFromAppDirectory(RuntimeLibrary runtimeLibrary) { if (CompileAssemblies.ContainsKey(runtimeLibrary.Name) && _libraries.ContainsKey(runtimeLibrary.Name)) return; - DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Processing dependency {1} {0} using .nuget packages and ApplicationDirectory path.", runtimeLibrary.Name, runtimeLibrary.Type); + DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Processing runtime dependency {1} {0} using .nuget packages and ApplicationDirectory path.", runtimeLibrary.Name, runtimeLibrary.Type); var asset = runtimeLibrary.Name; - if (!asset.EndsWith(".dll") && !asset.EndsWith(".sni")) - { - asset += ".dll"; - } - - if (asset == "runtime.native.System.dll") - { - asset = "System.dll"; - } + asset = ReplaceAssetName(asset); var assemblyPath = Path.Combine(_packagesPath, runtimeLibrary.Name.ToLower(), runtimeLibrary.Version, Path.GetFileName(asset)); @@ -478,13 +453,32 @@ private void AddDependencyFromAppDirectory(RuntimeLibrary runtimeLibrary) CompileAssemblies.TryAdd(runtimeLibrary.Name, assemblyPath); _libraries.TryAdd(runtimeLibrary.Name, assemblyPath); - DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Added dependency {1} from {0}", assemblyPath, runtimeLibrary.Name); + DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Added runtime dependency {1} from {0}", assemblyPath, runtimeLibrary.Name); AddSupplementaryRuntime(runtimeLibrary); } else { - DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Could not add dependency {0}", assemblyPath); + DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Could not runtime add dependency {0}", assemblyPath); + } + } + + private string ReplaceAssetName(string asset) + { + if (!asset.EndsWith(".dll") && !asset.EndsWith(".sni")) + { + asset += ".dll"; + } + + if (asset == "runtime.native.System.dll") + { + asset = "System.dll"; + } + + if (asset == "NETStandard.Library.dll") + { + asset = "netstandard.dll"; } + return asset; } private void AddCompileDependencies(DependencyContext dependencyContext, bool standalone)