[英]External dependencies in Azure functions with netcore
我已经能够用网络核心编写Azure功能来运行。 我现在已经添加了对“ WindowsAzure.Storage”的引用,并且当我使用本地测试环境(“ func host start”)时,我正在获得loaderexceptions。
我无法使用默认的表存储绑定程序,因为我需要在不同表中更新记录。
我使用预编译的函数,并且正在OSX上使用VSCode进行开发。 如果不支持此方案,我找不到任何信息。 甚至有可能使外部依赖项与Azure函数的2.0运行时一起工作。
本地SDK /运行时为
我的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.