IronLanguages / ironpython3

Implementation of Python 3.x for .NET Framework that is built on top of the Dynamic Language Runtime.
Apache License 2.0
2.51k stars 290 forks source link

Let IronPython Compiler only create one exe file when target to exe or winexe #1786

Open wherewhere opened 8 months ago

wherewhere commented 8 months ago

The issue is #1785 I add a new method CreateAssemblyGen in ClrModule to get AssemblyGen, so that I can add exe host code into ScriptCode assembly. Then I change the init code from

string currentDirectory = Environment.CurrentDirectory;
Environment.CurrentDirectory = new FileInfo(Assembly.GetEntryAssembly().Location).Directory.FullName;
string fullPath = Path.GetFullPath("bin/Program.dll");
Environment.CurrentDirectory = currentDirectory;
return PythonOps.InitializeModuleEx(Assembly.LoadFile(fullPath), "__main__", null, ignoreEnvVars: false, null);

to

return PythonOps.InitializeModuleEx(Assembly.GetExecutingAssembly(), "__main__", null, ignoreEnvVars: false, null);

since the ScriptCode assembly is itself. But now it have some new problem. Since the AssemblyBuilder dose not have DefineIconResource method, I have no ideal to add win32 icon. And the Windows Defender said it is viruses when /standalone option is on...

PS. I use reflection to invoke SavableScriptCode.CompileForSave since SavableScriptCode is in DLR repository. It is better to add CreateAssemblyGen method for SavableScriptCode.

wherewhere commented 8 months ago

Looks fine with .NET Core App image