0

I have the following post build event which should pack all the .NET framework dependencies into the .exe:

$(SolutionDir)packages\ILRepack.2.0.16\tools\ILRepack.exe
/out:"$(TargetDir)$(TargetName).all.exe" 
"$(TargetDir)$(TargetName).exe" 
"$(TargetDir)*.dll" 
/target:exe 
/targetplatform:v4,"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7.2" /wildcards

But it must not be packing everything, since when I run it inside a barebones Windows 7 x64 VM, a popup says .NET is required. After installing .NET 4.7.2 everything works fine.

Here is the ILRepack output:

4>------ Rebuild All started: Project: GenerateReport, Configuration: Release Any CPU ------
4>  GenerateReport -> C:\code\Thor\Main\pc\tools\ReportGenerator\GenerateReport\bin\Release\GenerateReport.exe
4>  INFO: IL Repack - Version 2.0.16
4>  INFO: ------------- IL Repack Arguments -------------
4>  /out:C:\code\Thor\Main\pc\tools\ReportGenerator\GenerateReport\bin\Release\GenerateReport.all.exe  C:\code\Thor\Main\pc\tools\ReportGenerator\GenerateReport\bin\Release\GenerateReport.exe C:\code\Thor\Main\pc\tools\ReportGenerator\GenerateReport\bin\Release\*.dll
4>  -----------------------------------------------
4>  INFO: Adding assembly for merge: C:\code\Thor\Main\pc\tools\ReportGenerator\GenerateReport\bin\Release\GenerateReport.exe
4>  INFO: Adding assembly for merge: C:\code\Thor\Main\pc\tools\ReportGenerator\GenerateReport\bin\Release\ICSharpCode.SharpZipLib.dll
4>  INFO: Adding assembly for merge: C:\code\Thor\Main\pc\tools\ReportGenerator\GenerateReport\bin\Release\MDIData.dll
4>  INFO: Adding assembly for merge: C:\code\Thor\Main\pc\tools\ReportGenerator\GenerateReport\bin\Release\MDIReporter.dll
4>  INFO: Processing references
4>  INFO: Processing types
4>  INFO: Merging <Module>
4>  INFO: Merging <Module>
4>  INFO: Merging <Module>
4>  INFO: Renaming <PrivateImplementationDetails> into <ea0a2b3c-dc31-41d4-9795-6271bac3aa6b><PrivateImplementationDetails>
4>  INFO: Merging <Module>
4>  INFO: Processing exported types
4>  INFO: Processing resources
4>  INFO: Fixing references
4>  INFO: Writing output assembly to disk
4>  INFO: Finished in 00:00:02.2785005

This is a C# console app built with "Any CPU".

The other two projects in my solution are .NET 4.7.2 desktop class libraries.

I've also tried ILMerge, but it fails with a reference to a thirdy party library that it can't follow. That reference I have embedded as a resource in my application and it works fine.

1 Answers1

0

ILRepack/ILMerge only merge the non .NET Framework dependencies into the final output (Unless you specifically try to merge framework assemblies). But you will still need the original .NET libraries to be available. So if you use 4.7.2, you need 4.7.2 on the target machine.

If you aim was to try and "lower" the targeted .NET Framework version (i.e., so it runs without anything else on Windows 7), then this won't work, you'll have to target .NET 4.0 (which is the default on Windows 7 after windows updates)

If you want a self-contained executable that doesn't require additional installations, you should take a look at .NET Core, which delivers the .NET framework alongside the app.

Timotei
  • 1,909
  • 2
  • 22
  • 31