简体   繁体   English

在门户网站编写的Azure函数中包括NuGet程序包

[英]Including a NuGet package in an Azure function written in the Portal

I have created a new Azure function in the portal, and wanted to use the WindowsAzure.Storage NuGet package. 我在门户中创建了一个新的Azure函数,并想使用WindowsAzure.Storage NuGet包。 Given that the default template is created with: 假定使用以下方式创建了默认模板:

#r "Newtonsoft.Json"

I thought I could do this: 我以为我可以这样做:

#r "WindowsAzure.Storage" 

However, when I do, I get the error: 但是,当我这样做时,出现错误:

[Error] run.csx(2,1): error CS0006: Metadata file 'WindowsAzure.Storage' could not be found

I can't see anywhere else that Newtonsoft.Json is being referenced. 我在其他地方看不到被引用的Newtonsoft.Json

How can I include this NuGet package in my function (without building this is VS or VS Code and deploying it). 我如何在函数中包含此NuGet包(不构建VS或VS Code并进行部署)。 Also, what, exactly does the #r directive do, if not bring in external libraries and packages? 另外,如果没有引入外部库和包,那么#r指令究竟能做什么?

Ok so everytime i create a Function app i mostly use VS Code or Visual Studio just for the intellisense and easiness of work. 好的,所以每次我创建一个Function应用程序时,我大多都是出于对智能和工作的便利性而使用VS Code或Visual Studio。 To add a nuget from the Azure portal 从Azure门户添加nuget

  1. Click on View Files and add a function.proj 单击View Files并添加一个function.proj

在此处输入图片说明

  1. Now add the below piece of code with any nuget do you need. 现在,在下面的代码中添加所需的任何nuget。
    <Project Sdk="Microsoft.NET.Sdk">
    <PropertyGroup>
        <TargetFramework>netstandard2.0</TargetFramework>
      </PropertyGroup>

      <ItemGroup>
        <PackageReference Include="WindowsAzure.Storage" Version="9.3.3"/>
      </ItemGroup>
    </Project>

upon saving this you should see the console update stating that the packages are getting installed. 保存后,您应该看到控制台更新说明正在安装软件包。 This really isn't well documented in the microsoft docs 微软文档中确实没有对此进行很好的记录

There is correction in namespace 名称空间中有更正

#r "Microsoft.WindowsAzure.Storage" #r“ Microsoft.WindowsAzure.Storage”

and not #r "WindowsAzure.Storage" 而不是#r“ WindowsAzure.Storage”

You can refer - https://docs.microsoft.com/en-us/azure/azure-functions/functions-reference-csharp#binding-to-arguments 您可以参考-https: //docs.microsoft.com/zh-cn/azure/azure-functions/functions-reference-csharp#binding-to-arguments

Try with #r "Microsoft.WindowsAzure.Storage" 尝试使用#r“ Microsoft.WindowsAzure.Storage”

You can also upload a custom dll into the function app by Kudu tools. 您还可以通过Kudu工具将自定义dll上传到功能应用中。 And then you can refer the dll by #r "path to dll" 然后您可以通过#r“ dll的路径”引用dll。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM