Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Target .NET Core 2.0 with Azure Functions in Visual Studio 2017

Tags:

Since Microsoft has released .NET Core 2.0 for Azure Functions a few days ago, I'm trying to understand how to create a new Functions project in VS2017 targeting .NET Core.

I've tried many configurations and still ended up with .NET 4.7.

Did anyone manage to create a new Function targeting .NET Core?

Thanks.

like image 658
NOP-MOV Avatar asked Oct 06 '17 15:10

NOP-MOV


People also ask

Can I use .NET core in Visual Studio 2017?

Visual Studio 2017 Support for . Among the workloads and project types, you can find support for . NET Framework, . NET Core, Mono, and . NET Native for Universal Windows Platform (UWP).

Do Azure functions support .NET core?

Azure Functions 2. x supports C# (. NET Core 2.2), JavaScript (Node 8 & 10), F# (. NET Core 2.2), Java 8, PowerShell Core 6, Python 3.7.

How do I create an Azure function app in Visual Studio 2017?

Add Azure Function ProjectOpen the Visual Studio and create a new project. Choose “Cloud” from the project template type list and then “Azure Functions” as the project type. Give a meaningful name to your project and click “OK”. To start with, choose Empty as a project type and click “OK” to create the project.

How do I run Azure function in Visual Studio?

From the Visual Studio menu, select File > New > Project. In Create a new project, enter functions in the search box, choose the Azure Functions template, and then select Next. In Configure your new project, enter a Project name for your project, and then select Create.


2 Answers

This is supported with the 1.0.5 release of the Microsoft.NET.Sdk.Functions package.

In your Azure Functions Project, do the following:

  • Update the Microsoft.NET.Sdk.Functions package version to 1.0.5
  • Right click on your project, click the Edit <projectname>.csproj option and modify the TargetFramework element value to netstandard2.0

This will should generate .NET Standard 2.0 assemblies with all the artifacts created by the Azure Functions tooling.

like image 88
Fabio Cavalcante Avatar answered Oct 01 '22 23:10

Fabio Cavalcante


As of today I have been able to target .Net Standard 2.0 in a "reasonably" intuitive way and without editing any .csproj files.

You need a reasonably recent version of Visual Studio. I'm using Visual Studio Professional 15.5.3 (although I would guess that community would work).

You need to have the Azure development workload installed. This will install an extension called Azure Functions and Web Jobs Tools.

So far so plain vanilla. There were 2 additional bits that were to me not at all intuitive but ended up being very easy to do - easy when you know how!

  1. You need to make sure that the Azure Functions and Web Jobs Tool is 15.0.31114.0 or greater - that's when they added .net core 2.0 support (see https://github.com/Azure/Azure-Functions/blob/master/VS-AzureTools-ReleaseNotes.md). You can update this using Tools/Extensions and Updates, or see https://marketplace.visualstudio.com/items?itemName=VisualStudioWebandAzureTools.AzureFunctionsandWebJobsTools

  2. Even when you've done that, Visual Studio is a tiny bit weird about letting you create Azure Functions that target .net 2.0. When you go File/New Project, nothing has changed in the list of available project types, and if you select Azure Functions, the list of Frameworks just shows .NET Framework *, no .NET Standard, no .NET Core.
    enter image description here

But if at this point you persevere and select Azure Functions, you then get a new dialog I hadn't seen before, which allows you to select Azure Functions v2 Preview (.NET Core).Azure Functions v2 Preview (.NET Core)

Now, when I then look at the project properties, it turns out it is targeting .NET Standard 2.0, which in turn seems to contain Microsfot.NETCore.Platforms (1.1.0). So is this .net core 2.0 or not? Not quite sure but its' good enough for my purposes so now going to tuck into some coding.

Cheers!

enter image description here

like image 28
ubienewbie Avatar answered Oct 01 '22 22:10

ubienewbie