gluck / il-repack

Open-source alternative to ILMerge
Apache License 2.0
1.19k stars 217 forks source link

Merge success reported, but assemblies not merged in publish folder #311

Closed emirmo closed 11 months ago

emirmo commented 2 years ago

Hi, my project is a Windows Forms application that uses the .NET Framework version 4.8. The project uses several external dependencies, and I'm hoping to merge them into a single assembly file for release.

Configuration

After installing the nuget package, my *.csproj file was updated with a new reference:

<PackageReference Include="ILRepack.Lib.MSBuild.Task" Version="2.0.18.2" />

Then, I added an ILRepack.targets file to the project root, with the following contents:

<?xml version="1.0" encoding="utf-8" ?>
<Project>
    <Target Name="ILRepacker" AfterTargets="Build">
        <ItemGroup>
            <InputAssemblies Include="$(OutputPath)\*.dll" />
        </ItemGroup>
        <ILRepack
            Parallel="true"
            Internalize="true"
            InternalizeExclude="@(DoNotInternalizeAssemblies)"
            InputAssemblies="@(InputAssemblies)"
            TargetKind="Dll"
            OutputFile="$(OutputPath)\$(AssemblyName).dll"
        />
    </Target>
</Project>

Problem

When I publish my project via the Visual Studio GUI, the Output tab reports success:

Merging 7 assembies to {my assembly}
Merge succeeded in {seconds}
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
========== Publish: 1 succeeded, 0 failed, 0 skipped ==========

When I open the Release/net48/publish folder, all dependencies are deployed, as if it were a regular, non-merged publish action. If I delete an assembly (e.g. "Newtonsoft.Json.dll") from the publish folder, and open my executable, an exception is thrown when the executable calls the assembly:

Could not load file or assembly 'Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The system cannot find the file specified.

It's the same with any other external dependency.

I'm wondering if I've missed something, because all assemblies are reported as correctly merged, but the published project files behave like regularly published, non-merged files.

Other

This may not necessarily be related, but when I try building the project via command line (rather than through the Visual Studio GUI):

dotnet build

the following error occurrs:

The "ILRepack" task could not be loaded from the assembly {my path}.nuget\packages\ilrepack.lib.msbuild.task\2.0.18.2\build\ILRepack.Lib.MSBuild.Task.dll. Could not load file or assembly 'Microsoft.Build.Utilities.v4.0, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified. Confirm that the <UsingTask> declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask.

mjesteve commented 1 year ago

Hi, Were you able to solve it?

lextm commented 1 year ago

You come to the wrong place. That MSBuild task you used has nothing to do with this repo, but Repack.Lib.MSBuild.Task/issues so you should go there and contact its developers.

mjesteve commented 1 year ago

I was confused at first :)

KirillOsenkov commented 11 months ago

Yes, this should probably go to https://github.com/ravibpatel/ILRepack.Lib.MSBuild.Task/issues. Although I suspect the latest version of the task NuGet may fix it: https://www.nuget.org/packages/ILRepack.Lib.MSBuild.Task/2.0.22