首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在最新的蔚蓝网络作业3.03中指定AzureWebJobsStorage

如何在最新的蔚蓝网络作业3.03中指定AzureWebJobsStorage
EN

Stack Overflow用户
提问于 2019-01-04 16:49:42
回答 2查看 3.9K关注 0票数 2

我更新了我以前的蓝色网页作业代码,将其打包成3.03,然后它就不起作用了。

我设法修复了所有编译时错误,但在本地运行时,它会引发以下错误:

代码语言:javascript
运行
复制
Microsoft.Azure.WebJobs.Host.Indexers.FunctionIndexingException
  HResult=0x80131500
  Message=Error indexing method 'MvQueueProcessorV2.ProcessMVRequest'
  Source=Microsoft.Azure.WebJobs.Host
  StackTrace:
   at Microsoft.Azure.WebJobs.Host.RecoverableException.TryRecover(ILogger logger) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Exceptions\RecoverableException.cs:line 81
   at FE.Toolkit.MvPaaS.WebJob.Program.<Main>(String[] args)

Inner Exception 1:
InvalidOperationException: Storage account 'Storage' is not configured.

对我来说,这似乎表明它找不到设置AzureWebJobsStorage?但是,它在app.config文件中睡得很好。因此,我假设我应该将连接字符串放入appsettings.json,所以这就是我在appsettings.json中所做的:

代码语言:javascript
运行
复制
{
  "ConnectionStrings": {
    "AzureWebJobsDashboard": "xxx",
    "Storage": "yyy"
  }
}

然而,它给了我同样的错误。那么,如何设置WebJob3.0的存储空间呢?

这是我在program.cs中的代码

代码语言:javascript
运行
复制
var builder = new HostBuilder()
              .UseEnvironment("Development")
              .ConfigureWebJobs(b =>
               {
                 b.AddAzureStorageCoreServices()
                   .AddAzureStorage()
                   .AddTimers()
                   .AddFiles()
                   .AddDashboardLogging();
                   })
                  .ConfigureLogging((context, b) =>
                 {
                   b.SetMinimumLevel(LogLevel.Debug);
                   b.AddConsole();
                  })
                   .ConfigureServices(services =>
                  {
                        services.AddSingleton<INameResolver, ConfigNameResolver>();
                  })
               .UseConsoleLifetime();
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-01-07 02:04:36

请在您的program.cs中添加以下代码:

代码语言:javascript
运行
复制
.ConfigureAppConfiguration((context, config) => {
                    config.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true);
                })

我已经在我身边测试过了,而且工作得很好。

Program.cs中的代码:

代码语言:javascript
运行
复制
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;

namespace WebJob1template
{
    class Program
    {
        static void Main()
        {

            var builder = new HostBuilder()
                .UseEnvironment("Development")
                .ConfigureAppConfiguration((context, config) => {
                    config.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true);
                })
                .ConfigureWebJobs(
                b =>
                {
                    b.AddAzureStorageCoreServices()
                    .AddAzureStorage()
                    .AddTimers()
                    .AddFiles();
                    //.AddDashboardLogging();
                })
                .ConfigureLogging((context, b) =>
                {
                    b.SetMinimumLevel(LogLevel.Debug);
                    b.AddConsole();
                })
                .UseConsoleLifetime();


            var host = builder.Build();

            using (host)
            {
                host.Run();
            }
        }
    }
}

Appsettings.json(请注意,将其属性“复制到输出目录”设置为“始终复制”):

代码语言:javascript
运行
复制
{
  "ConnectionStrings": {
    "AzureWebJobsDashboard": "xxxx",
    "AzureWebJobsStorage": "xxxx"
  }
}

Function.cs:

代码语言:javascript
运行
复制
using Microsoft.Azure.WebJobs;
using Microsoft.Extensions.Logging;

namespace WebJob1template
{
    public class Functions
    {        
        public static void ProcessQueueMessage([QueueTrigger("queue")] string message, ILogger log)
        {
            //log.WriteLine(message);
            log.LogInformation(message);
        }
    }
}

测试结果:

票数 2
EN

Stack Overflow用户

发布于 2019-05-17 01:41:25

我遇到了同样的问题,这是我的解决办法

下面是我指的Azure程序集

使用上述设置,如果配置文件名为“c.AddJsonFile("appsettings.json", ... )”,则不需要调用appSettings.json。

默认情况下,框架将查找名为“appsettings.json”的文件

但是,如果文件名是其他东西,我们需要告诉HostBuilder配置文件的名称是什么。

代码语言:javascript
运行
复制
HostBuilder builder = new HostBuilder();

//Below piece of code is not required if name of json file is 'appsettings.json'
builder.ConfigureAppConfiguration(c =>
{
   c.AddJsonFile("Myappsettings.json", optional: false, reloadOnChange: true);

});

在本地机器上调试时引起问题的简单而重要的步骤是'appsettings.json‘文件的’Copy to Output Directory‘属性。@Ivan Yang在他的答复中已经提到了这一点。

这里是源代码的git链接。

注意:我遵循这份文件来实现代码库。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54043029

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档