il-repack icon indicating copy to clipboard operation
il-repack copied to clipboard

Merge success reported, but assemblies not merged in publish folder

Open emirmo opened this issue 2 years ago • 0 comments

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.

emirmo avatar May 04 '22 09:05 emirmo