loading...
Microsoft Azure

Develop Azure Functions using .NET Core 3.1

jeffhollan profile image Jeff Hollan Updated on ・4 min read

<< 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

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

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

Posted on by:

jeffhollan profile

Jeff Hollan

@jeffhollan

PM for Azure Functions. I do what I love - and I love serverless

Microsoft Azure

Any language. Any platform.

Discussion

markdown guide
 

Hi,
I get these errors in this preview:
Microsoft.Data.SqlClient is not supported on this platform.
System.Drawing is not supported on this platform.

 
 

Can you let me know the package you are pulling in that is causing this, and how you are using it? Any steps I can take to repro would be great.

I created an issue on GitHub. I'm getting the same thing. My suspicion is that it's coming from Entity Framework

github.com/Azure/Azure-Functions/i...

issue comes from Microsoft.EntityFrameworkCore.SqlServer when calls DB.
System.Drawing also in any call will get error.

Do you know of a workaround / fix?

Someone got back to me on my GitHub Issue (github.com/Azure/Azure-Functions/i...) with a workaround that fixes this.

Sorry for not getting back to you earlier" been super busy in ignite planning! Great to see there is a workaround. Will test it ASAP!

Not sure where this landed but as an FYI just tested using both Entity Framework and SQL server on v3 bits and worked fine. Here's my repo: github.com/jeffhollan/functions-ch...

3.1 works perfectly. Good job.

 

When trying to pull in a netcore3.0 logging component we've written, it complains with the following.

Error System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Extensions.Logging.Abstractions, Version=3.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.
File name: 'Microsoft.Extensions.Logging.Abstractions, Version=3.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'
at System.Signature.GetSignature(Void* pCorSig, Int32 cCorSig, RuntimeFieldHandleInternal fieldHandle, IRuntimeMethodInfo methodHandle, RuntimeType declaringType)
at System.Reflection.RuntimeMethodInfo.FetchNonReturnParameters()
at System.Reflection.RuntimeMethodInfo.GetParameters()
at MakeFunctionJson.MethodInfoExtensions.GetDisabled(MethodInfo method)
at MakeFunctionJson.MethodInfoExtensions.HasUnsuportedAttributes(MethodInfo method, String& error)
at MakeFunctionJson.FunctionJsonConverter.GenerateFunctions(IEnumerable1 types)+MoveNext()
at System.Collections.Generic.List
1.AddEnumerable(IEnumerable1 enumerable)
at System.Linq.Enumerable.ToList[TSource](IEnumerable
1 source)
at MakeFunctionJson.FunctionJsonConverter.TryGenerateFunctionJsons()
at MakeFunctionJson.FunctionJsonConverter.TryRun()

Error generating functions metadata
Logging.UserAgent C:\Users\user.nuget\packages\microsoft.net.sdk.functions\1.0.30-beta2\build\Microsoft.NET.Sdk.Functions.Build.targets 41

 

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.

 

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

 

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...

 

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

 
 

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]

 

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

 

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

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

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...

Ok let me see if I can repro

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'
 

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.

 

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]

 

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'
 

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.

 

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...

 
 

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.

 

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

 

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

 

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"

 

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

 

The main issue we have is that it’s incompatible with net standard 2.1.

If function project A exposes a class from net standard project B, when B is 2.0 everything works, when B is 2.1 the solution won’t even compile anymore.

This issue has been blocking since release with no comment from maintainers, are you able to have someone look into it?

 

Came across this post by sheer luck last night - and tried it out. Works great! I can confirm Azure Function v3 with Microsoft Graph Auth works really well. Also really nice to use Null coalescing assignment and in-built Json Serializer. May I never have to hear "Newtonsoft" by choice ever again ;)

 

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?

 

The Git Repository that this Azure Fx package mentioned nuget.org/packages/Microsoft.NET.S...

is not having code related to 1.0.30-beta2 , and neither in Release section of git repo 1.0.30-beta2 is mentioned as Released.

github.com/Azure/azure-functions-v... , in branches there is branch for beta1 but not for beta2 , not sure why it is so ?

 

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...

 

Error generating functions metadata because of Microsoft.AspNetCore.Mvc.Abstractions, Version=3.0.0.0 , see: github.com/Azure/azure-functions-v...

 

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 :*****(

 

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?

 

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?

 
 

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

 

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

 

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).

 

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 :)

 

\o/
Good news, can't wait until .NET Core 3.0 is available everywhere in Azure, without having to install additional extensions.

 
 

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

 

I was able to see the preview in the drop down yesterday but today I cannot. I posted an issue on github github.com/Azure/azure-functions-h....

 

Another way to get around this is just running the version of func.exe that you want. You can do this by changing the debug settings of the csproj to
C:\Users\xxxx\AppData\Local\AzureFunctionsTools\Releases\3.0.2\cli\func.exe and a parameter of start.

 

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

 

Thanks, I am not but hopefully they fix this mapping problem of versions before it gets out of preview ;)

 

Can I use F# or do you have templates for it?

 

Yep! Have a few templates you can install via NuGet and dotnet cli here github.com/Azure/azure-functions-t... or VS Code will list and use if you select to view “All” templates github.com/microsoft/vscode-azuref...

 

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

 

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