DEV Community

Jeff Hollan for Microsoft Azure

Posted on • Updated on

Develop Azure Functions using .NET Core 3.1

<< Updated on Dec 9 2019 with go-live announcement of Azure Functions on .NET Core 3.1 >>

We're extremely excited to announce you can now develop and publish Azure Functions built on top of the .NET Core 3.1 runtime.

Things to know

Azure Functions 3.0 is now go-live and ready for production. It is a highly backwards compatible release. One of the immediate benefits of this release is you can write Azure Functions targeting netcoreapp3.1. You should also be able to move existing ~2 apps to ~3 without issue. A list of considerations on changes between 2.x and 3.x can be found in our docs.

You can write any Azure Function language in 3.0 (Java, JavaScript, PowerShell, TypeScript, Python) - though note some of the tooling and integrations will continue to receive updates until mid-January. Instructions on changing your tools or apps to target 3.x for other languages can be found in our docs. For now let's walk through creating a .NET Core 3.1 app.

Getting started

Install the .NET Core 3.1 SDK

Install the 3.x core tools (optional for Visual Studio development)

Using npm:

npm install -g azure-functions-core-tools@3
Enter fullscreen mode Exit fullscreen mode

Using brew:

brew tap azure/functions
brew install azure-functions-core-tools@3
# If you already have func installed
brew link --overwrite azure-functions-core-tools@3
Enter fullscreen mode Exit fullscreen mode

Create an Azure Functions project

You have a few options here. You could create a new project using our Visual Studio, Visual Studio Code, or CLI tools. For other tools, once you install the 3.x core tools you should be set. If attempting to target .NET Core 3.1 just be sure to update your .csproj file template with netcoreapp3.1. Also be sure to target the `Microsoft.NET.Sdk.Functions package version of at least 3.0.1.

Creating with Visual Studio 2019

If you want to develop using .NET Core 3.1, you must use Visual Studio 2019 16.4 or newer.

  1. Open Visual Studio and select to create a new Azure Functions project
    • You should see an indicator at the bottom as it downloads the runtime and templates of "Making sure all templates are up to date." This could take a few minutes, but wait for it to finish.
  2. Once the templates are up to date, go back one screen and forward so template options are refreshed.
  3. Select the now available "Azure Functions v3" option from the template drop-down.
  4. Create your project.
  5. If you want to target .NET Core 3.1, edit the project properties and select .NET Core 3.1.

You should be set! You can now debug, test, and publish this function.

Publish your Function App

You can publish your function using the regular tools. Depending on the tool you will likely see a prompt to update your FUNCTIONS_EXTENSION_VERSION application setting from the default ~2 to ~3. This does need to occur before a 3.x app can run successfully in Azure.

Upgrading a v2 app to v3

If you have an existing app and want to test it out with the new release, the following settings would need to be modified:

Non-.NET Functions

Locally once you start using the 3.x CLI your apps will debug and run in the 3.0 environment automatically. For apps in the cloud, you simply need to update the app setting of FUNCTIONS_EXTENSION_VERSION to ~3 - but make sure to do some validation tests first before changing anything in production 😅.

.NET Functions

If using Visual Studio, make sure you've already followed all of the steps in the "Creating with Visual Studio 2019" section to ensure you have the latest templates and project options available before attempting to upgrade. You may need to go to the new app template screen to get the 3.x bits to pull in on your machine, so if you get an error like "no runtime available that matches the version," try creating a new 3.x app from scratch first to make sure VS has fetched all the latest bits.

To change a project between ~2 and ~3 locally, update the .csproj file of the project and change:

  • AzureFunctionsVersion from v2 to v3
  • Microsoft.NET.Sdk.Functions package version to at least 3.0.1
  • Optionally, you can change to target netcoreapp3.1 if you want to target the latest .NET Core version

You should not change the host.json version to 3.0. The host.json schema version is different than the function runtime version, and is still 2.0.

Path to GA

While you can begin using 3.x in production today, we are tracking a few work items around tooling and platform features before we announce full GA for tools and runtime in January 2020. You can see some of those work items called out in GitHub

Latest comments (61)

Collapse
 
anskanth profile image
anskanth

Hey
Wondering if you have any solution/alternates for the problem I posted in here realted to deployment slots.. stackoverflow.com/questions/633845...

It's a bit bigger one but for sure an interesting one :)

Collapse
 
abmismi profile image
abmis-mi

Hi,
I want to add app insights logging to Azure Function v3 as we do in Web Jobs v3 like:
builder.ConfigureLogging((context, logging) =>
{
logging.AddApplicationInsightsWebJobs(o => o.InstrumentationKey = appInsightsKey);
});

I tried similar code there but it didn't work.
builder.Services.AddLogging(builder => {
builder.AddApplicationInsights(appInsightsKey);
});

Is there a documented way of adding app insights to azure functions in code?

Collapse
 
eliashdezr profile image
Elias Hdez

Overall, dependency injection issues has been since the .NET Core 3.0 release. Can you follow up this please? @jeffhollan

github.com/Azure/azure-functions-d...

and this

github.com/Azure/azure-functions-d...

Collapse
 
andreasohlund profile image
Andreas Öhlund

Are there any known issues with app insights when running locally?

Previously I could inject a TelemetryConfiguration into my function but since updating to v3 from the preview it blows up with:

Microsoft.Extensions.DependencyInjection.Abstractions: Unable to resolve service for type 'Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration'

Not tested if this works when publishing though.

Collapse
 
andreasohlund profile image
Andreas Öhlund

Ie this no longer works locally docs.microsoft.com/en-us/azure/azu...

Collapse
 
jeffhollan profile image
Jeff Hollan

No known issue but I imagine this is due to in conflicting with its own configuration and potentially something changed between versions. I’d open up a GitHub issue for this one

Collapse
 
andreasohlund profile image
Andreas Öhlund

Thanks, raised github.com/Azure/azure-functions-h... , seems to be more ppl with the same issue.

Collapse
 
eliashdezr profile image
Elias Hdez • Edited

Overall, dependency injection issues has been since the .NET Core 3.0 release. Can you follow up this please?

github.com/Azure/azure-functions-d...

and this

github.com/Azure/azure-functions-d...

Collapse
 
cmendibl3 profile image
Carlos Mendible

Hi Jeff is there a preview version of the Docker image so I can update my mcr.microsoft.com/azure-functions/dotnet:2.0 refs?

Collapse
 
zpertee20 profile image
zach pertee

Ditto. I also badly need this feature. Can I simply update my dockerfile to install .net core 3 or is there more to it than that?

Collapse
 
jeffhollan profile image
Jeff Hollan

We have them published mcr.microsoft.com/azure-functions/...

Thread Thread
 
zpertee20 profile image
zach pertee

Thanks Jeff!

Thread Thread
 
cmendibl3 profile image
Carlos Mendible

Thanks dude!

Collapse
 
chartloginc profile image
Chartlog

After spending the entire day to try to get this working I have finally given up. I was in the midst of trying to automate my ef migrations using azure pipelines and ran into an issue where generated migration scripts would have syntactical issues described here

github.com/aspnet/EntityFrameworkC...

This led me to upgrade to ef core 3, which led me down a cascade of events in upgrading my solution to .netcore 3 and .net standard 2.. I will have to resort to manually running migrations on each release :*****(

Collapse
 
dapoulin profile image
David Poulin • Edited

Hey,

Just a fast feedback on my experience with Azure Functions using net core 3.0
I was feeling quite lazy about installing another preview of visual studio 2019, so i kept using my current version (16.3.8).

My main prerequisite was to install the latest version of the azure function preview tools (i did it on powershell).

How i got using my azure function .net core 3.0 (with net standard library 2.1 ?).

1/ Creating azure function with vs 2019 (non preview)
2/ change in csproj AzureFunctionsVersion from v2 to v3
3/ update Microsoft.NET.Sdk.Functions to 1.0.30-beta2 (the 3.xxx does not work for me).
Each time i tried to debug with vs, i got a crash.
4/ Then, tried to start my project with command lines ( func start --build )
5/ Every thing goes well locally and when deployed to azure

On Azure portal, I only had to activate the runtime preview (v3). nothing else.

As you can not debug with my solution, you will have to use efficiently logging (everyone is supposed to do it right ;p).

Collapse
 
markatagilliance profile image
Mark Davies

Cautionary note. I had a working function and re-factored to put one of the function service dependencies in its own .net standard library. It stopped working.

If you get an error like
FunctionApp1: Method not found: 'Microsoft.Extensions.DependencyInjection.IServiceCollection Microsoft.Azure.Functions.Extensions.DependencyInjection.IFunctionsHostBuilder.get_Services()'.
Then you may be missing the crucial step I missed : setting the AzureFunctionsVersion from v2 to v3-preview in the project file. It worked as V2 as a single project function and only stopped working when I separated the injected dependency service into its own library. HTH.

Collapse
 
felicss profile image
felicss

Did this actually solve the problem for you? I am still getting the same error, even with v3-preview

Collapse
 
felicss profile image
felicss

Fixed it => the latest preview-release of the Microsoft.EntityFrameworkCore 3.1.0-preview3 seems to cause the problem

Collapse
 
patricknolan profile image
Patrick • Edited

Hi Jeff,

I have followed your article and my solution is compiling and running in my dev environment using .NET Core 3.0 but behind my Azure build Pipeline I get the following error. Could you please offer any suggestions?

It was not possible to find any compatible framework version [/home/vsts/work/1/s/blah.csproj]
error : The specified framework 'Microsoft.NETCore.App', version '2.1.0' was not found.
error : - The following frameworks were found: [/home/vsts/work/1/s/blah.csproj]
error : 3.0.0 at [/opt/hostedtoolcache/dotnet/shared/Microsoft.NETCore.App]
error : [/home/vsts/work/1/s/blah.csproj]

Collapse
 
jeffhollan profile image
Jeff Hollan

Your app is set to target 2.1 so your build agent will need a 2.x version. Reads that build agent only has 3.x. Other option is change app target is csproj to netcoreapp3.0

Collapse
 
patricknolan profile image
Patrick

Hi Jeff thanks heaps for your response it hugely appreciated!

My .csproj file currently contains the following. Would you then expect the Azure build pipeline to target 3.0 and not 2.1?


netcoreapp3.0
v3-preview

Thread Thread
 
jeffhollan profile image
Jeff Hollan

Hmm if that’s what your csproj says maybe the problem is the other way around. Can you confirm the devops agent has and is using dotnet 3? I don’t know where the 2.1 would come from if it’s not in your csproj file

Thread Thread
 
patricknolan profile image
Patrick • Edited

I'm executing a "use .NET Core" step beforehand which is set to version 3.0.x. I noticed John D'Alessandro also posted here with the same issue :(

I also tried setting the Agent Specification to windows-2019 value as suggested here stackoverflow.com/questions/565741...

Thread Thread
 
jeffhollan profile image
Jeff Hollan

Ok let me see if I can repro

Thread Thread
 
jeffhollan profile image
Jeff Hollan

Was able to repro. Found a bug. Tracked here: github.com/Azure/azure-functions-v...

workaround is to make sure 2.x is on the build box as well. I changed my deploy script to this and it worked in the interim.

- task: UseDotNet@2
  inputs:
    packageType: 'sdk'
    version: '2.1.x'
- task: UseDotNet@2
  inputs:
    packageType: 'sdk'
    version: '3.0.x'
Collapse
 
smimon profile image
smimon

After running "npm install -g azure-functions-core-tools@preview", I do not have version 3 available in the C:\Users[User]\AppData\Local\AzureFunctionsTools\Releases folder - highest version is still 2.42.0

Any ideas how to pull in the preview version? Thanks

Collapse
 
smimon profile image
smimon

Never mind, I found instructions on how to download it manually from here github.com/Azure/azure-functions-t...

Collapse
 
smartymind profile image
Smartymind • Edited

Thanks for this updated information about what visual studio must be used. Maybe it is our fault behavior but we was not checking this article everyday so we did not get this notice before we updated visual studio to newest version therefore the development has stopped. Do you have any idea how could we install a specific version of visual studio 2019 community? I've found only links to professional and enterprise versions here.

Collapse
 
colbytresness profile image
Colby Tresness

Hey there - we're really sorry that we had to make this change. Unfortunately it was necessary in order to prevent breaking old versions of Visual Studio once we take the experience out of preview. We don't expect it will happen again.

This should help: docs.microsoft.com/en-us/visualstu...

Collapse
 
smartymind profile image
Smartymind

This link did not help.

Collapse
 
sjscheidertt profile image
sjscheider-tt

I had this working for a couple weeks now. After an OS update, I think that is the culprit, I'm getting the following error when I try to run any functions is Visual Studio.

"There is no Functions runtime available that matches the version specified in the project"

Collapse
 
sjscheidertt profile image
sjscheider-tt

A co-working of mine was able to figure this one out with the assistance of this link:
github.com/Azure/azure-functions-t...

In the file feed.json (C:\Users\[user]\AppData\Local\AzureFunctionsTools\feed.json): it defines all capable versions you can debug in VS.
The feed.json updates automatically and for some reason the information for v3-preview disappeared for both my co-worker and I.

So we just "hardcoded" the executable path under Properties > Debug for the project.
Set the executable to: C:\Users\[user]\AppData\Local\AzureFunctionsTools\Releases\3.0.3\cli\func.exe
Set application arguments to: start

Collapse
 
jagge123 profile image
jagge123

Did all the steps above and still no sign of Azure Functions v3 Preview - option in the drop down. Any ideas?

Collapse
 
colbytresness profile image
Colby Tresness

You're likely not on the latest VS 2019 Preview. What version are you using?

Collapse
 
miguelesteban profile image
miguelEsteban

+1

Collapse
 
colbytresness profile image
Colby Tresness

Update to the latest Visual Studio 2019 preview if you're still having this issue.

Collapse
 
jdaless profile image
John D'Alessandro • Edited

I'm having trouble building a v3-preview project in my DevOps Git repo CI pipeline. Despite applying all of the upgrade steps you gave it's still looking for a Microsoft.NETCore.App 2.1.0 framework. dotnet build works locally. Deployment also works locally, and I have my function app running just fine, but not having CI/CD is a bottleneck.

Collapse
 
patricknolan profile image
Patrick • Edited

Hi John I'm encountering the same issue. Did you find a solution?

It is compiling and running in my dev environment using .NET Core 3.0 but behind my Azure build Pipeline I get the following error

It was not possible to find any compatible framework version [/home/vsts/work/1/s/blah.csproj]
error : The specified framework 'Microsoft.NETCore.App', version '2.1.0' was not found.
error : - The following frameworks were found: [/home/vsts/work/1/s/blah.csproj]
error : 3.0.0 at [/opt/hostedtoolcache/dotnet/shared/Microsoft.NETCore.App]
error : [/home/vsts/work/1/s/blah.csproj]

Collapse
 
jeffhollan profile image
Jeff Hollan

Was able to repro. Found a bug. Tracked here: github.com/Azure/azure-functions-v...

workaround is to make sure 2.x is on the build box as well. I changed my deploy script to this and it worked in the interim.

- task: UseDotNet@2
  inputs:
    packageType: 'sdk'
    version: '2.1.x'
- task: UseDotNet@2
  inputs:
    packageType: 'sdk'
    version: '3.0.x'