Skip to content

Commit 6ec895b

Browse files
committed
Removed LoadLibrary hack on windows
1 parent 156928d commit 6ec895b

File tree

2 files changed

+7
-21
lines changed

2 files changed

+7
-21
lines changed

src/Dotnet.Script.Core/ScriptCompiler.cs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
using System.Collections.Immutable;
44
using System.Linq;
55
using System.Reflection;
6-
using System.Runtime.InteropServices;
76
using System.Text;
87
using System.Threading.Tasks;
98
using Dotnet.Script.Core.Internal;
@@ -24,10 +23,6 @@ namespace Dotnet.Script.Core
2423
{
2524
public class ScriptCompiler
2625
{
27-
// Note: Windows only, Mac and Linux needs something else?
28-
[DllImport("Kernel32.dll")]
29-
private static extern IntPtr LoadLibrary(string path);
30-
3126
private ScriptEnvironment _scriptEnvironment;
3227

3328
private Logger _logger;
@@ -120,8 +115,6 @@ public virtual ScriptCompilationContext<TReturn> CreateCompilationContext<TRetur
120115

121116
scriptOptions = AddScriptReferences(scriptOptions, loadedAssembliesMap, scriptDependenciesMap);
122117

123-
LoadNativeAssets(runtimeDependencies);
124-
125118
AppDomain.CurrentDomain.AssemblyResolve +=
126119
(sender, args) => MapUnresolvedAssemblyToRuntimeLibrary(scriptDependenciesMap, loadedAssembliesMap, args);
127120

@@ -150,17 +143,6 @@ private RuntimeDependency[] GetRuntimeDependencies(ScriptContext context)
150143
}
151144
}
152145

153-
private void LoadNativeAssets(RuntimeDependency[] runtimeDependencies)
154-
{
155-
foreach (var nativeAsset in runtimeDependencies.SelectMany(rtd => rtd.NativeAssets).Distinct())
156-
{
157-
if (_scriptEnvironment.IsWindows)
158-
{
159-
LoadLibrary(nativeAsset);
160-
}
161-
}
162-
}
163-
164146
private ScriptOptions AddScriptReferences(ScriptOptions scriptOptions, Dictionary<string, Assembly> loadedAssembliesMap, Dictionary<string, RuntimeAssembly> scriptDependenciesMap)
165147
{
166148
foreach (var runtimeAssembly in scriptDependenciesMap.Values)

src/Dotnet.Script.Core/ScriptPublisher.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,15 @@ private string CreateScriptAssembly<TReturn, THost>(ScriptContext context, strin
129129

130130
foreach (var runtimeDependency in emitResult.RuntimeDependencies)
131131
{
132-
foreach (var nativeAsset in runtimeDependency.NativeAssets)
132+
if (!runtimeDependency.Name.Contains("microsoft.netcore", StringComparison.OrdinalIgnoreCase))
133133
{
134-
if (!runtimeDependency.Name.Contains("microsoft.netcore", StringComparison.OrdinalIgnoreCase))
134+
foreach (var nativeAsset in runtimeDependency.NativeAssets)
135135
{
136-
File.Copy(nativeAsset,Path.Combine(outputDirectory, Path.GetFileName(nativeAsset)), true);
136+
File.Copy(nativeAsset, Path.Combine(outputDirectory, Path.GetFileName(nativeAsset)), true);
137+
}
138+
foreach (var runtimeAssembly in runtimeDependency.Assemblies)
139+
{
140+
File.Copy(runtimeAssembly.Path, Path.Combine(outputDirectory, Path.GetFileName(runtimeAssembly.Path)), true);
137141
}
138142
}
139143
}

0 commit comments

Comments
 (0)