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

后端 未结 3 1230
别跟我提以往
别跟我提以往 2021-01-03 21:57

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.

相关标签:
3条回答
  • 2021-01-03 22:44

    For now, it's a manual process. You need to create .NET Standard 2.0 library, add function.json manually and run it with core tools.

    the package Microsoft.NET.Sdk.Functions does not yet support .NET Standard 2.0 class libraries. This is the package that identifies a project as Functions project to Visual Studio and generates function.json from attributes during build.

    You can still author C# class libraries that target .NET Standard 2.0, but you must use a manually-authored function.json. The templates for C# class libraries aren’t yet available in the Core Tools, but you can get a sample from GitHub.

    from Develop Azure Functions on any platform

    Update: 1.0.5 version of SDK should now support it, as mentioned by Fabio.

    0 讨论(0)
  • 2021-01-03 22:52

    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.

    0 讨论(0)
  • 2021-01-03 22:56

    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.

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

    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!

    0 讨论(0)
提交回复
热议问题