Home > Software engineering >  How to use external dependencies in a Google Cloud Function?
How to use external dependencies in a Google Cloud Function?

Time:07-19

I am new to Google Cloud Function and have zero knowledge of cloud computing in general. I have been trying to figure out how to import and use external dependencies (let's say RestClient or Newtonsoft's Json library for C#) in Google Cloud Function (I have also been instructed to code with Google Cloud Shell).

In Visual Studio, we would use Nuget to manage external libraries. How do I install or import external libraries so that I could use them in my Google Cloud Function?

CodePudding user response:

Define them in the *.csproj file (or add them with an IDE).
Specifying dependencies in .NET provides an example for that.
As usual, one needs to know the package name and it's version.

I'd suggest to learn from an IDE, how it edits the *.csproj file -
then you'll know exactly what to manually type/paste into there.

The dotnet add package CLI command does merely the same;
it's basically all about adding a new line into the *.csproj file.

dotnet add package RestClient.Net --version 5.1.0

One can not only use Nuget from the GUI, but also in PowerShell:
https://docs.microsoft.com/en-us/nuget/reference/ps-reference/ps-ref-install-package

Install-Package Newtonsoft.Json

Comparing the versions of the *.csproj file before and after, will show you the edits it made.
Even without dotnet or Nuget CLI installed, one can always manually edit the *.csproj file.

  • Related