question

RyanAbbey-0701 avatar image
0 Votes"
RyanAbbey-0701 asked SandervandeVelde42 answered

Import packages to Azure Function

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
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Creating a function.proj file and trying to upload returns the error

"Failed to upload 'function.proj'. Uploading files over 5MB is not supported from the Azure portal"

The file is 1KB in size!!

0 Votes 0 ·

1 Answer

SandervandeVelde42 avatar image
0 Votes"
SandervandeVelde42 answered

Hello @RyanAbbey-0701,

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.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.