Azure Function学习随笔

2019/9/3

Portal上面的nuget包也是可以配置的,需要注意的是V2不再支持Function.json,需要使用Function.proj
两篇相关的帖子:
https://stackoverflow.com/questions/36411536/how-can-i-use-nuget-packages-in-my-azure-functions
https://blogs.msdn.microsoft.com/cjaliaga/2018/01/21/installing-nuget-packages-in-azure-functions-2-x-runtime-preview/

2019/9/4

有一个非常普遍的问题就是FileNotFound,在python当中则是表示为import error: cannot … not file or directory.

Azure Function依赖注入的包

<PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="3.1.0" />
<PackageReference Include="Microsoft.Extensions.Http" Version="3.1.0" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.29" />
var config = new ConfigurationBuilder()
                .SetBasePath()
                .AddJsonFile("CustomSettings.json", optional: true, reloadOnChange: true)
                .AddEnvironmentVariables()
                .Build();

Log文件的位置

D:\home\LogFiles\Application\Functions\Host

遇到Function unable to Start

有时候这种问题并不意味着任何错误,解决方法可能是重新启动Function即可

一般情况下时AzureStorage的设置问题或者时Storage本身访问防火墙的问题

The listener for function is unable to start

问题可能来自于防火墙和虚拟网络的设置,或者整个复制到新的项目,或者就是链接String错误

IBinder的使用

using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;

namespace FunctionApp27
{
    public static class Function1
    {
        [FunctionName("Function1")]
        public static async Task<IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
            IBinder binder,
            ILogger log)
        {
            using (var outputStream = await binder.BindAsync<Stream>(new BlobAttribute("test/20201023.txt", FileAccess.Write) { Connection="str"}))
            {
                await req.Body.CopyToAsync(outputStream);
            }
            return new OkObjectResult("This is a test.");
        }
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值