Visual Studio 2017 Tools for Azure Functions

Web Development Tools Microsoft

Visual Studio 2017 Tools for Azure Functions are now available as part of the Azure development workload starting in the Visual Studio 2017 15.3 release. These tools:

  • Enable creating pre-compiled C# functions that bring better cold start performance than script based functions, and opens the entire eco-system of Visual Studio tools for class libraries including code analysis, unit testing, complete IntelliSense, 3rd party extensions, etc.
  • Uses WebJobs attributes to declare function bindings directly in the C# code rather than the separate function.json file.

clip_image002

Getting Started

To get started:

To create a new project, choose File -> New Project, and the Azure Functions project type

image

This will create an empty project which contains the following files:

  • host.json enables configuring the function host
  • local.settings.json which stores setting information such as connection strings used for running the function on the development machine. Note: For all trigger types except HTTP, you need to set the value of AzureWebJobsStorage to a valid Azure Storage account connection string.

To add a function to the application right click the project and choose “Add Item”, then choose the “Azure Function” item template. This will launch the Azure Function dialog that enables you to choose the type of function you want, and enter any relevant binding information. For example, in the dialog below, the queue trigger asks you for the name of the connection string to the storage queue, and the name of the queue (path).

image

This generates a new class that has the following elements:

  • A static Run method, that is attributed with [FunctionName] attribute. The [FunctionName] attribute indicates that the method is the entry for an Azure Function.
  • The first parameter has a QueueTrigger attribute, this is what indicates is a queue trigger function (and takes the binding information as parameters to the attribute. In this case the name of the queue and the connection string’s setting name)

Once you have a function, local development works like you would expect. You can run and debug it locally, add NuGet packages, create unit tests, and anything else you would do for a class library.

clip_image008

To publish a Function project to Azure directly from Visual Studio, right click the project and choose “Publish”. On the publish page, you can either create a new Function App in Azure or publish to an existing one. Note: even though the Folder option is currently appears, it’s not intended for use with Azure Functions at this time.

clip_image010

It’s also possible to configure continuous delivery using Visual Studio Team Services.

Question and Answer

I installed Visual Studio 2017 15.3 and the Azure development workload, but I don’t see the Azure Functions project type or am receiving an error trying to build or run a function app: While pulled in automatically by the Azure development workload, Azure Function tools are distributed via the Visual Studio gallery which gives us the flexibility to update them as needed to react to changes on the Azure side which don’t always happen on the Visual Studio schedule. If for some reason the tools don’t get automatically updated from the gallery, in Visual Studio, go to Tools | Extensions and Updates, and look at the “Updates” tab. If it shows an update is available for “Azure Functions and Web Job Tools” manually update them by clicking the “Update” button.

How can I file issues or provide feedback on these tools? You can file issues or provide feedback on the Azure Functions GitHub repo by prefixing them with [Visual Studio]

Are these targeting .NET Standard 2.0 as outlined in the roadmap post? At this time the Functions Runtime does not yet support .NET Standard libraries. So these are .NET Standard class library projects, but the build target is set to .NET 4.6.1. In the future, when the Functions runtime support .NET Standard you will simply need to change the target framework.

I have existing functions written as .csx scripts, how do I port those to the new precompiled project type? To convert a .csx file into a new function you will need to move the Run method into a class, remove #load, and replace #r with assembly or project to project references (see complete steps).

What about support for F# functions? It will be possible to create Azure Functions in Visual Studio using F# in a future update, but support is not included in this release.

What is the plan for the Visual Studio 2015 tools? The Visual Studio 2015 tooling was an initial preview that got us a lot of great feedback and we learned a lot from them. Given our pivot to pre-compiled functions with the intent to focus on .NET Standard 2.0, we have dependencies that only exist in Visual Studio 2017 Update 3 and beyond, so there are no plans to release any future updates for Visual Studio 2015. Once the Functions runtime supports .NET Core, it will be possible to work with Azure Functions in Visual Studio Code as well as Visual Studio 2017 if you prefer or are unable to upgrade to Visual Studio 2017.

Conclusion

We’re very happy to be releasing our first version of support tools for Azure Function development in Visual Studio, so please let us know how they work for you. You can do that below, in the Azure Functions GitHub repo, or via twitter at @AndrewBrianHall and @AzureFunctions.

0 comments

Discussion is closed.

Feedback usabilla icon