Specify dependencies in .NET

.NET Cloud Run functions use Microsoft Build Engine (MSBuild) project files. These files are central to the build and deployment process. For C# the file extension is .csproj, for F# it is .fsproj, and for Visual Basic it is .vbproj.

For example, here is the .csproj file for the C# Hello World sample:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net6.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Google.Cloud.Functions.Hosting" Version="2.2.1" />
  </ItemGroup>
</Project>

You can add libraries to your function's project file as follows:

dotnet add package MY_LIBRARY

The Functions Framework is a required dependency for all functions. Although Cloud Run functions installs it on your behalf when the function is created, we recommend that you include it as an explicit dependency for clarity.

If your function relies on private dependencies, we recommend that you mirror functions-framework to your private registry. Include the mirrored functions-framework as a dependency to your function to avoid installing the package from the public internet.

For more discussion of dependencies and other types of customization, see Customization through Functions Startup classes.