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

Top comments (61)

Collapse
 
hamedsayy profile image
Hamed • Edited

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.

Collapse
 
jakobgsvendsen profile image
Jakob G. Svendsen

+1

Collapse
 
jeffhollan profile image
Jeff Hollan • Edited

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.

Thread Thread
 
mswilson4040 profile image
Marc

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

Thread Thread
 
hamedsayy profile image
Hamed

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

Thread Thread
 
mswilson4040 profile image
Marc

Do you know of a workaround / fix?

Thread Thread
 
mswilson4040 profile image
Marc

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

Thread Thread
 
jakobgsvendsen profile image
Jakob G. Svendsen

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!

Thread Thread
 
jeffhollan profile image
Jeff Hollan

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

Thread Thread
 
hamedsayy profile image
Hamed

3.1 works perfectly. Good job.

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'
Collapse
 
doogdeb profile image
doogdeb

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

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
 
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
 
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
 
andreasohlund profile image
Andreas Öhlund

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

Collapse
 
andreasohlund profile image
Andreas Öhlund

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

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
 
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
 
avishar profile image
Vijay

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?

Collapse
 
mrsimonc profile image
Mr Simon C

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

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