Skip to content

embed Python.Runtime.dll in nPython #38

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 10, 2014
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions pythonnet/src/console/Console.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,9 @@
</ItemGroup>
<ItemGroup>
<Content Include="python-clear.ico" />
<EmbeddedResource Include="$(PythonBuildDir)\Python.Runtime.dll">
<LogicalName>Python.Runtime.dll</LogicalName>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
Expand Down
27 changes: 26 additions & 1 deletion pythonnet/src/console/pythonconsole.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
// ==========================================================================

using System;
using System.Reflection;
using Python.Runtime;

namespace Python.Runtime {
Expand All @@ -27,6 +28,30 @@ public static int Main(string[] args) {
return i;
}

}
// Register a callback function to load embedded assmeblies.
// (Python.Runtime.dll is included as a resource)
private sealed class AssemblyLoader {
public AssemblyLoader() {
AppDomain.CurrentDomain.AssemblyResolve += (sender, args) => {
String resourceName = new AssemblyName(args.Name).Name + ".dll";

// looks for the assembly from the resources and load it
using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName)) {
if (stream != null) {
Byte[] assemblyData = new Byte[stream.Length];
stream.Read(assemblyData, 0, assemblyData.Length);
return Assembly.Load(assemblyData);
}
}

return null;
};
}
};

private static AssemblyLoader assemblyLoader = new AssemblyLoader();

};


}