0

不知何故,我无法使用Microsoft.Azure.Storage.blobcsx 在 Azure Function v2 中使用包。

在 extension.proj 我有以下内容:

<PackageReference Include="Microsoft.Azure.Storage.Blob" Version="11.1.0" />

在 csx 文件中,我有:

using Microsoft.Azure.Storage;
using Microsoft.Azure.Storage.Blob;

我有错误:

run.csx(7,23): error CS0234: The type or namespace name 'Storage' does not exist in the namespace 
'Microsoft.Azure' (are you missing an assembly reference?)

完整代码在 GitHub 上:https ://github.com/ptrstpp950/cognitive-service-azure-function

4

2 回答 2

1

1.你确定extension.proj你正在使用吗?

从您的代码中,我知道您正在门户网站上写作。所以你应该创建function.proj而不是extension.proj在门户上。

2.我看到你写<PackageReference Include="Microsoft.Azure.Storage.Blob" Version="11.1.0" />在 .proj 文件中。所以你应该使用#r "Microsoft.WindowsAzure.Storage"而不是 using Microsoft.WindowsAzure.Storage

下面是我的代码,function.proj我这边一切正常。有关更多详细信息,请查看此官方文档。(所有解决方案都基于您正在使用function 2.x。如果您正在使用function 1.x。它是不一样的。)

<Project Sdk="Microsoft.NET.Sdk">
    <PropertyGroup>
        <TargetFramework>netstandard2.0</TargetFramework>
    </PropertyGroup>

    <ItemGroup>
        <PackageReference Include="Microsoft.Azure.Storage.Blob" Version="11.1.0" />
    </ItemGroup>
</Project>

在此处输入图像描述

我的 .crx 文件的代码:

#r "Newtonsoft.Json"
#r "Microsoft.WindowsAzure.Storage"

using System.Net;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Primitives;
using Newtonsoft.Json;
using Microsoft.Azure.Storage.Blob;

public static async Task<IActionResult> Run(HttpRequest req, ILogger log)
{
    log.LogInformation("C# HTTP trigger function processed a request.");

    string name = req.Query["name"];

    string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
    dynamic data = JsonConvert.DeserializeObject(requestBody);
    name = name ?? data?.name;

    return name != null
        ? (ActionResult)new OkObjectResult($"Hello, {name}")
        : new BadRequestObjectResult("Please pass a name on the query string or in the request body");
}
于 2019-10-16T01:49:59.330 回答
0

您应该在使用之前导入包:

#r "Microsoft.WindowsAzure.Storage"
using Microsoft.WindowsAzure.Storage.Table;
using Microsoft.Extensions.Logging;
于 2019-10-15T14:29:13.917 回答