update to NET Core 3.0
I'm not aware of any issues caused by running Hangfire in .NET Core 3.0 applications. It's distributed as a package that includes a netstandard2.0 package that's fully compatible with .NET Core 3.0.
It even works with the Worker Service template with Hangfire.NetCore package referenced:
using Hangfire;
using Microsoft.Extensions.Hosting;
namespace WorkerService2
{
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureServices((hostContext, services) =>
{
services.AddHangfire(config => config.UseSqlServerStorage("connection_string"));
services.AddHangfireServer();
});
}
}
If there is no problem, I use it for the project
In version 1.7.7 on netcoreapp3.0 AddHangfireServer() is not available
@rchybicki, are you sure?
@odinserj It's good that you asked, after you wrote I checked again and was able to make it work. For anyone that might encounter the same:
-I updated from 1.6 to 1.7 while updating from netcoreapp 2.2 to 3.0 using paket upgrade.
-I got the services.AddHangfireServer() is unavailable error. I checked that on another project I'm using services.AddHangfireServer() with aspnetcore3 and 1.7.6.
-I downgraded to 1.7.6, still no services.AddHangfireServer()
@odinserj Actually I have some problems after upgrade to .net core 3.0
According to this https://docs.microsoft.com/en-us/aspnet/core/migration/22-to-30?view=aspnetcore-3.0&tabs=visual-studio
There are some packages referenced by Hangfire.AspNetCore never produced after .net core 3.0
<PackageReference Include="Microsoft.AspNetCore.Hosting.Abstractions" Version="2.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Antiforgery" Version="2.0.0" />
And error occurs onced I add Hangfire.AspNetCore to my project
Cannot find reference assembly 'Microsoft.AspNetCore.Antiforgery.dll' file for package Microsoft.AspNetCore.Antiforgery.Reference
System.InvalidOperationException: Cannot find reference assembly 'Microsoft.AspNetCore.Antiforgery.dll' file for package Microsoft.AspNetCore.Antiforgery.Reference
at Microsoft.Extensions.DependencyModel.Resolution.ReferenceAssemblyPathResolver.TryResolveAssemblyPaths(CompilationLibrary library, List`1 assemblies)
at Microsoft.Extensions.DependencyModel.Resolution.CompositeCompilationAssemblyResolver.TryResolveAssemblyPaths(CompilationLibrary library, List`1 assemblies)
at Microsoft.Extensions.DependencyModel.CompilationLibrary.ResolveReferencePaths(ICompilationAssemblyResolver resolver, List`1 assemblies)
at Microsoft.Extensions.DependencyModel.CompilationLibrary.ResolveReferencePaths()
Modify Hangfire.AspNetCore.csproj would work
modify
<TargetFrameworks>net451;net461;netstandard1.3;netstandard2.0;netcoreapp3.0</TargetFrameworks>
add
<ItemGroup Condition="'$(TargetFramework)'=='netcoreapp3.0'">
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="3.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="3.0.0" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)'=='netcoreapp3.0'">
<FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>
I believe you shoud refactor and have the IHostBuilder code on a new nuget package, keeping only the dashboard and aspnet specific stuff on the Hangfire.AspNetCore package, since you can AddHostedService on aspnet core.
Most helpful comment
If there is no problem, I use it for the project