Hangfire icon indicating copy to clipboard operation
Hangfire copied to clipboard

Failed to resolve assembly: Newtonsoft.Json when using ILRepack.Lib.MSBuild.Task

Open testsys-murali opened this issue 1 year ago • 1 comments

Hi there -- I am encountering the following error when trying to use the Hangfire.Core and ILRepack.Lib.MSBuild.Task NuGet libraries. Can someone please assist me with this issue? Thanks.

Error:

Failed to resolve assembly: 'Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'

Steps to Reproduce:

  1. Download the ~5KB CS Project file: HangfireILRepack.zip
  2. Perform a Debug Build – notice that after pulling the NuGet libraries, it works.
  3. Perform a Release Build – notice the error mentioned above.

testsys-murali avatar Sep 27 '24 15:09 testsys-murali

There's an open issue regarding this, please see https://github.com/ravibpatel/ILRepack.Lib.MSBuild.Task/issues/26. The simplest solution would be to create and reference the ILRepack.targets in the project directory with the following contents:

<Project>
    <Target Name="ILRepacker" AfterTargets="Build" Condition="$(Configuration.Contains('Release'))">
        <ItemGroup>
            <InputAssemblies Include="$(OutputPath)$(TargetName)$(TargetExt)"/>
            <InputAssemblies Include="@(ReferencePathWithRefAssemblies)" Condition="'%(filename)' == 'Newtonsoft.Json'" />
            <InputAssemblies Include="@(ReferencePathWithRefAssemblies)" Condition="'%(filename)' == 'Hangfire.Core'" />
            <InputAssemblies Include="@(ReferencePathWithRefAssemblies)" Condition="'%(filename)' == 'Owin'" />
        </ItemGroup>

        <ILRepack
                Parallel="true"
                DebugInfo="true"
                AllowDuplicateResources="false"
                InputAssemblies="@(InputAssemblies)"
                TargetKind="SameAsPrimaryAssembly"
                KeyFile="$(KeyFile)"
                OutputFile="$(OutputPath)$(TargetName)$(TargetExt)"
        />
    </Target>
</Project>

odinserj avatar Sep 30 '24 05:09 odinserj