HangfireIO / Hangfire

An easy way to perform background job processing in .NET and .NET Core applications. No Windows Service or separate process required
https://www.hangfire.io
Other
9.35k stars 1.69k forks source link

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

Open testsys-murali opened 5 days ago

testsys-murali commented 5 days ago

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.
odinserj commented 2 days ago

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>