Azure, C#, Visual Studio

The moment I came to play with .NET Standard 2.0 – Azure Functions

2 min read

A lot has changed ever since I played with Azure Functions and .NET Standard 2.0. If you remember from my previous post, I was talking about how you had to set the FUNCTIONS_EXTENSION_VERSION to beta in order to benefit from the new runtime. I also talked about how I had a problem with the connection manager to access the app settings.

Well the good news is that the team now fully migrated to the new Configuration modeling from ASP.NET core. You can now easily refer to your configurations by importing the following packages and using the following code to have access to your configuration:

Nuget package Description
Microsoft.Extensions.Logging Main logging package
Microsoft.Extensions.Logging.Abstractions Makes SetBasePath() available
Microsoft.Extensions.Logging.Json Makes AddJsonFile() method available
Microsoft.Extensions.Configuration.EnvironmentVariables Makes AddEnvironmentVariables() method available

Visual Studio

The template in Visual Studio 2017 for Azure Function is targeted for the .NET framework. If you want to play with .NET Standard 2.0, you will need to target Azure Functions Version 2.

This is especially important if you want to use EntityFramework Core 2.1 and over in your function.

To change the target framework and Azure Function version of your Azure Function app, you will need to edit the csproj. In the PropertyGrouptag, replace the TargetFramework and AzureFunctionsVersion tags to the following:

You also will need to install the latest Azure Functions Core Tools through npm. Debugging is also an important step when we program. In order to be able to debug, you will need to add a debugging profile. Azure Function staffs provides some information about this here.

In case you care unable to access the page, here’s a quick summary:

  1. Install the Azure Functions Core Tools from NPM. The core tag will have the latest version: npm i -g azure-functions-core-tools@core --unsafe-perm true
  2. In your function project properties, under Debug create a new profile and update the following values:
    1. Launch: Executable
    2. Executable: dotnet.exe
    3. Application arguments: %userprofile%\AppData\Roaming\npm\node_modules\azure-functions-core-tools\bin\func.dll host start (NOTE: this path may differ if you’re using NVM. You can use npm root -g to find the exact path to the node_modules folder)

If you wish you can directly modify your launchSettings.json and add another profile (under the “profiles” section) with the following:

Don’t forget to update your Azure Functions and Web Jobs Tools extension to the latest version.

Happy coding!