Share via

Import packages to Azure Function

Ryan Abbey 1,186 Reputation points
2021-07-27T22:19:25+00:00

I'm trying to write an Azure function to unzip a large file and with that comes importing various libraries which I put at the top of my "run.csx" file.

I have created my AF using the portal and on clicking the "Test-Run", I get a warning "You may be referencing NuGet packages incorrectly. Learn more: https://go.microsoft.com/fwlink/?linkid=2091419". Following that link it says

"To use NuGet packages in a 2.x and later C# function, upload a function.proj file to the function's folder"
and
"For 1.x functions, use a project.json file instead"

Now the portal development environment gives a "function.json", is that the same as a "function.proj" or "project.json"? I'm assuming I'm using a "2.x and later" environment (think I chose 3.1 - only choice in fact) but don't know how to be certain?

So, should I be creating a separate file or using "function.json" (just noticed it is XML as the format so suspect it is a separate file)?
The libraries I'm led to believe I need are
System.IO.Compression;
Microsoft.Azure;
Microsoft.WindowsAzure.Storage;
Microsoft.WindowsAzure.Storage.Blob;

so how do I translate that in to the format the "help" file suggests, namely:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
    <PackageReference Include="Microsoft.ProjectOxford.Face" Version="1.1.0" />
</ItemGroup>

</Project>

Are they just a set of "PackageReference"s? What about version? Or do I need more?

Azure Functions
Azure Functions

An Azure service that provides an event-driven serverless compute platform.


1 answer

Sort by: Most helpful
  1. Sander van de Velde | MVP 37,066 Reputation points MVP
    2021-12-22T18:50:03.173+00:00

    Hello @Ryan Abbey ,

    adding NuGet package references in the portal is not a pleasant experience.

    Yes, you can upload a function.proj file like this with a nugget package in it:

    <Project Sdk="Microsoft.NET.Sdk">  
      <PropertyGroup>  
        <TargetFramework>netstandard2.0</TargetFramework>  
      </PropertyGroup>   
      <ItemGroup>  
        <PackageReference Include="Azure.Messaging.ServiceBus" Version="7.5.1" />  
      </ItemGroup>  
    </Project>  
    

    I got that 5MB message too, no idea why. But just retry it. Or, if an empty file is created, copy that text into it and try to save it.

    That said, I use the portal just to demonstrate stuff. I recommend working with the Azure Function project template (either in Visual Studio or Visual Studio Code).

    The investment in getting started is worth it! You will gain so much eg. version control, a proper editor, proper debugging.

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.