【问题标题】:Azure WebJobs in .NET Core Using VS 2017 15.3.NET Core 中的 Azure WebJobs 使用 VS 2017 15.3
【发布时间】:2018-01-08 23:54:55
【问题描述】:

刚刚安装了 Visual Studio 2017 15.3 的预览版,但我仍然看不到在 .NET Core 中创建 WebJobs 的方法。这是否可用 - 即使作为预览版或测试版 - 或不可用?

PS:这不是版主建议的重复问题。我只是说在另一篇文章中提出的建议不起作用。

【问题讨论】:

标签: .net-core visual-studio-2017 azure-webjobs azure-webjobssdk


【解决方案1】:

使用 .NET Core Framework 创建 WebJob 的方式有点不同。你需要使用 控制台应用程序(.NET Core)

我强烈建议您遵循本指南Azure WebJobs In .NET Core



这是我的简单 WebJob 的工作示例:(使用 Core 2.2)

程序

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();
    }
}

(我的班级:)

希望对你有帮助!

【讨论】:

  • 请不要贴代码截图,贴代码!
猜你喜欢
  • 1970-01-01
  • 2018-08-18
  • 2018-01-31
  • 2018-01-30
  • 1970-01-01
  • 2017-07-30
  • 2018-03-18
  • 2017-08-03
  • 1970-01-01
相关资源
最近更新 更多