gluck / il-repack

Open-source alternative to ILMerge
Apache License 2.0
1.16k stars 214 forks source link

Am I misunderstanding ILRepack / ILMerge #349

Closed Aetherinox closed 5 months ago

Aetherinox commented 7 months ago

Does this application allow for merging DLL files only into one DLL, or does it also allow for DLL files to be merged into an EXE so that you only have to carry around a single exe.

Because I'm searching for the latter of the two, and after messing with it for a bit, it only seems to merge my DLLs, unless I'm missing some of the functionality of it.

KirillOsenkov commented 7 months ago

it’s both, you merge into a dll or an exe

Aetherinox commented 7 months ago

Thanks for the reply. Am I possibly doing something wrong then?

ILRepack.exe /out:"H:\Projects\demo\bin\Release\net481\publish\demoproject.exe" /lib:"H:\Projects\demo\bin\Release\net481\publish" /out:"H:\CSharpProjects\demo\bin\Release\net481\publish\demoproject.exe" "H:\Projects\demo\bin\Release\net481\publish\System.Management.Automation.dll"

Using absolute paths is what got me results, but all I was attempting to test was integrating the Powershell automation DLL into my exe. However, after the process completes, you can't launch the exe. It actually says that the program cannot be ran by windows, almost as if it's corrupted.

The overall project has 4 DLLs, but I've just been trying to do one for now just to test with and confirm that I can still access those features within the exe after the merge is complete.

I do get an affirmative back from ILRepack

Wrote H:\Projects\demo\bin\Release\net481\publish\demoproject.exe

But then I receive: bGaMbby

KirillOsenkov commented 7 months ago

your /out is specified twice

Aetherinox commented 7 months ago

Sorry, bad copy/paste from terminal. Yeah it only had one /out, just checked.

The size increases, but the file becomes corrupted.

ILRepack.exe /out:"H:\Projects\demo\bin\Release\net481\publish\demoproject.exe" /lib:"H:\Projects\demo\bin\Release\net481\publish" "H:\Projects\demo\Release\net481\publish\System.Management.Automation.dll"

Is the actual command that was ran.

Actually tried another DLL, and that time, the size of the exe dramatically went down from 200kb to 11kb. The DLL was 21KB

KirillOsenkov commented 7 months ago

oh, indeed, you can’t merge with a .NET apphost exe, it’s not a managed assembly. Merge with demoproject.dll, not demoproject.exe.

We should report an error when we detect this case.

KirillOsenkov commented 7 months ago

look into PublishSingleFile perhaps

Aetherinox commented 7 months ago

Thanks, I'll take a look.

I keep on .net 4.8.1 because most people have a lot of those libraries, including Powershell (the automation DLL), but I tried net8, and that powershell DLL is roughly 8MB. So I'd have to ship an 8MB file along with a 200kb exe, which just seems really odd.

I'll see what I can do with publish single file and try to play with this more.

Aetherinox commented 7 months ago

Just an update.

I spent 5 or so hours messing with all of this.

I was able to successfully do exactly what I wanted with the older ILMerge. The only thing of note was that the DLLs had to be merged in a certain order otherwise a series of random errors would occur, even stack exceptions.

But after running the exe on a brand new system, all the features work.

I now need to see if I can take that same process and try it with ILRepack. But I was able to do it with ILMerge just fine by building the exe and then utilizing the command-line.

I could have used SingleFilePublish on NET 8, however, that version requires more DLLs to be integrated with my program, including an 8MB Powershell DLL for me to run powershell commands. Whereas with .net 4.8.1, that automation DLL is provided with all fresh installs of Windows and is not a dependency that needs to be messed with.

So the only option to make this is the easiest, was to stick with 4.8.1, and then get ILMerge / ILRepack to integrate the libraries I did actually need.

KirillOsenkov commented 6 months ago

Keeping the issue open to issue an error when we attempt to merge a native exe/dll.

Would you mind pasting the exact command line you ended up using with ILMerge? I'm still curious if there's an actual bug in ILRepack here (other than you can't merge the apphost exe).

Aetherinox commented 6 months ago

Sure thing. To make it easier, I just created a batch file to run the build

SET ILMERGE_VERSION=3.0.41
SET PATH_ILMERGE=%USERPROFILE%\.nuget\packages\ilmerge\%ILMERGE_VERSION%\tools\net452

"%PATH_ILMERGE%"\ILMerge.exe bin\Publish\demoapp.exe  ^
    /lib:bin\Publish ^
    /out:bin\Publish\demoapp.exe ^
    System.Buffers.dll ^
    System.Numerics.Vectors.dll ^
    System.Memory.dll

Was relatively straight forward with ILMerge. I haven't had a lot of time lately, but I do want to go back and try again with li repack. I'd rather use the updated program and not rely on the old version.

But as long as I combine the DLLs in this order, everything works perfect.

Ran the exe on my main desktop, and also in a virtual machine to make sure everything was included, and both machines worked great with the single exe.

KirillOsenkov commented 5 months ago

Let me know if you still see issues. If there are still problems I'll need a detailed repro and the logs (/verbose /log:log.txt)