簡體   English   中英

使用Netcore的Azure函數中的外部依賴關系

[英]External dependencies in Azure functions with netcore

我已經能夠用網絡核心編寫Azure功能來運行。 我現在已經添加了對“ WindowsAzure.Storage”的引用,並且當我使用本地測試環境(“ func host start”)時,我正在獲得loaderexceptions。

我無法使用默認的表存儲綁定程序,因為我需要在不同表中更新記錄。

我使用預編譯的函數,並且正在OSX上使用VSCode進行開發。 如果不支持此方案,我找不到任何信息。 甚至有可能使外部依賴項與Azure函數的2.0運行時一起工作。

本地SDK /運行時為

  • Azure Functions核心工具(2.0.1-beta.21)
  • 函數運行時版本:2.0.11370.0

我的csproj文件

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.Azure.WebJobs" Version="3.0.0-beta3" />
    <PackageReference Include="Microsoft.Azure.WebJobs.Extensions" Version="3.0.0-beta3" />
    <PackageReference Include="WindowsAzure.Storage" Version="8.6.0" />
  </ItemGroup>
  <ItemGroup>
    <Reference Include="Microsoft.CSharp" />
  </ItemGroup>
  <ItemGroup>
    <None Update="host.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="SearchTwitter\function.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="local.settings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </None>
  </ItemGroup>
</Project>

我功能的一部分

namespace MyProject.Functions
{
    public class SearchFunction
    {

        public async static Task Run(TimerInfo myTimer, Binder binder, TraceWriter log)
        {

            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(System.Environment.GetEnvironmentVariable("StorageConnection", EnvironmentVariableTarget.Process));
            CloudTableClient tableClient = storageAccount.CreateCloudTableClient();
            CloudTable searchMetaDataTable = tableClient.GetTableReference("SearchMetaData");
            await searchMetaDataTable.CreateIfNotExistsAsync();

        }
 }

Function.json

{
    "bindings": [
        {
            "type": "timerTrigger",
            "direction": "in",
            "schedule": "0 */15 * * * *",
            "runOnStartup": true,
            "name": "myTimer"
        }
    ],
    "scriptFile": "../MyProject.Functions.dll",
    "entryPoint": "MyProject.Functions.SearchFunction.Run"
}

默認情況下,Azure Functions托管環境可以使用Azure存儲命名空間。 您可以在此處找到更多詳細信息: https : //docs.microsoft.com/zh-cn/azure/azure-functions/functions-reference-csharp#referencing-external-assemblies

但是,如果這不是您想要的,請放心,您可以通過將任何外部NuGet軟件包添加到Function的csproj文件中來使用它。 有關如何執行此操作的示例,請在此GitHub存儲庫中查看示例代碼https://github.com/lindydonna/CSharpHttpCore/blob/master/HttpTriggerCore/HttpTriggerCore.csproj

對於預編譯的函數, WindowsAzure.Storage軟件包是Microsoft.NET.Sdk.Functions子依賴項,因此您無需單獨引用它。

如果仍然引用它,而引用的版本不正確,那么到處都會發生沖突。

對於Microsoft.NET.Sdk.Functions任何子依賴項,都應采取這種措施。 否則,將完全支持引用NuGets。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM