6

Just installed the preview version of Visual Studio 2017 15.3 but I still don't see a way to create WebJobs in .NET Core. Is this available -- even as a preview or beta -- or not?

PS: This is NOT a duplicate question as suggested by moderators. I'm simply stating that the suggestion made in the other post did NOT work.

enter image description here

Sam
  • 26,817
  • 58
  • 206
  • 383

1 Answers1

0

With .NET Core Framework the way to create a WebJob it's a bit different. You need to use Console Application(.NET Core).

I highly recommend you to follow this guide Azure WebJobs In .NET Core



This is my working example of simple WebJob :(Using Core 2.2)

(Program)

public class Program
{
    public static IConfigurationRoot config { get; private set; }

    static void Main(string[] args)
    {
        var environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
        Console.WriteLine($"Current Environment : {(string.IsNullOrEmpty(environment) ? "Development" : environment)}");

        config = new ConfigurationBuilder()
                .SetBasePath(Directory.GetCurrentDirectory())
                .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
                .AddJsonFile($"appsettings.{environment}.json", optional: true, reloadOnChange: true)
                .AddEnvironmentVariables()
                .Build();

        Console.WriteLine("URL API:" + config["appsettings node"]);


        var builder = new HostBuilder()
            .ConfigureWebJobs(webJobConfiguration =>
            {
                webJobConfiguration.AddTimers();
                webJobConfiguration.AddAzureStorageCoreServices();
            })
            .ConfigureServices(serviceCollection => serviceCollection.AddSingleton<TimeneyeTasks>())
            .Build();

        builder.Run();
    }
}

(My class:) enter image description here

I hope it helps!!

Sergio M.
  • 88
  • 1
  • 7