ravibpatel / ILRepack.Lib.MSBuild.Task

MSBuild task for ILRepack which is an open-source alternative to ILMerge.
Other
107 stars 30 forks source link

Problem with duplicate Types #21

Open THHoekstra opened 4 years ago

THHoekstra commented 4 years ago

When using the TaskScheduler package (https://github.com/dahall/taskscheduler) in a project and using ILRepack to merge all assemblies, I get the following error:

error : Duplicate type System.Collections.Generic.EventedList`1 from GroupControls.dll, was also present in AeroWizard, Version=2.2.3.0, Culture=neutral, PublicKeyToken=915e74f5d64b8f37

Obviously, the same type is present in two repedent packages. How can I configure ILRepack to handle this problem?

ravibpatel commented 4 years ago

You can try providing ILRepack.targets similar to the following one in your projects folder.

<!-- ILRepack -->
<?xml version="1.0" encoding="utf-8" ?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <Target Name="ILRepacker" AfterTargets="Build" Condition="'$(Configuration)' == 'Release'">

    <ItemGroup>
        <InputAssemblies Include="$(OutputPath)\ExampleAssemblyToMerge1.dll" />
        <InputAssemblies Include="$(OutputPath)\ExampleAssemblyToMerge2.dll" />
        <InputAssemblies Include="$(OutputPath)\ExampleAssemblyToMerge3.dll" />
    </ItemGroup>

    <ILRepack
        Parallel="true"
        Internalize="true"
        InputAssemblies="@(InputAssemblies)"
        TargetKind="Dll"
        OutputFile="$(OutputPath)\$(AssemblyName).dll"
        AllowedDuplicateNamespaces="System.Collections.Generic.*"
    />

    </Target>
</Project>
<!-- /ILRepack -->
THHoekstra commented 4 years ago

Thank you for your answer. Does that mean I have to specify every assembly to include? I was hoping for an option similar to /allowDup in "ILMerge"

ravibpatel commented 4 years ago

Yes, You have to provide targets file to use AllowedDuplicateNamespaces option which should work similarly to /allowDup. You can use something like the following if you don't want to write every dll into the targets file.

<!-- ILRepack -->
<?xml version="1.0" encoding="utf-8" ?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <Target Name="ILRepacker" AfterTargets="Build" Condition="'$(Configuration)' == 'Release'">

    <ItemGroup>
      <InputAssemblies Include="$(OutputPath)$(TargetName)$(TargetExt)"/>
      <InputAssemblies Include="$(OutputPath)*.dll" Exclude="$(OutputPath)$(TargetName)$(TargetExt)"/>
    </ItemGroup>

    <ILRepack
      Parallel="true"
      DebugInfo="true"
      AllowDuplicateResources="false"
      InputAssemblies="@(InputAssemblies)"
      TargetKind="SameAsPrimaryAssembly"
      AllowedDuplicateNamespaces="System.Collections.Generic.*"
      OutputFile="$(OutputPath)$(TargetName)$(TargetExt)"
    />

    </Target>
</Project>
<!-- /ILRepack -->
THHoekstra commented 4 years ago

Thanks again. That looks good. I will try this.

THHoekstra commented 4 years ago

My build fails without any Error Message in the output. How can I find out what's wrong with my targets file?

ravibpatel commented 4 years ago

Try providing a LogFile option. It should show up in the log.

ravibpatel commented 4 years ago

Or you can use MSBuild Log Viewer.