functions_color
Azure Functions

The serverless computing realm of cloud computing has been growing in interest and functionality lately. Recently, Azure Functions reached General Availability and an eagerly anticipated v1.0 release. Microsoft has not stopped there, in fact they just recently released a Preview of the new Visual Studio Tools for Azure Functions. These tools bring Azure Functions support into the Visual Studio IDE!

Visual Studio Tools for Azure Functions Preview

The new Visual Studio Tools for Azure Functions is currently in a Preview release state. As a result, the tools aren’t fully complete yet, and as with any Preview release it can be expected that things may / will change a bit before the final release. All preview releases can be expected to have some rough spots, bugs, and limitations. That being stated…

The requirements to install the Visual Studio Tools for Azure Functions are:

  • You must be running Visual Studio 2015 Update 3 with the “Microsoft Web Developer Tools” extension installed.
  • You must have Azure 2.9.6 .NET SDK installed.
vsazurefunctionstoolspreviewinstaller01

Once you have the following prerequisites installed, you can go ahead to download and install the Visual Studio Tools for Azure Functions Preview.

Create New Azure Functions Project

Once the Visual Studio Tools for Azure Functions Preview is installed, you can easily create a new Azure Functions project within Visual Studio 2015 from the New Project dialog. It is located under the Cloud section under Visual C#.

vsazurefunctionspreview_newproject

Even though the Azure Function (Preview) project template is located underneath the Visual C# -> Cloud section, you are able to create / author Azure Functions in non-C# languages within the project after creation.

vsazurefunctionspreview_addfunctionmenu

To add a New Azure Function to the project, just following these steps:

  1. Right-click on the Project within the Solution Explorer window.
  2. Click on Add, then New Azure Function…
  3. Within the New Azure Function dialog, select the Azure Function template in your choice language from the list.

The list of languages supported for authoring Azure Functions within the Visual Studio Tools for Azure Functions is inclusive of all the languages supported by Azure Functions. This makes the tool much more flexible than if it were to only support C# and JavaScript as the current editor UI does within the Azure Portal.

vsazurefunctionspreview_addfunctionlanguagedropdown

The Azure Functions languages supported include:

  • Bash
  • Batch
  • C#
  • F#
  • JavaScript
  • PHP
  • PowerShell
  • Python

In addition to choosing the language template for the Azure Function to add to the project, there are also many different templates to choose from including different types of Triggers that will be setup for the Azure Function. Not all the languages support all the different Trigger types and Function templates from the New Azure Functions dialog, but there is a fairly long list currently available; especially for C# and Javascript.

vsazurefunctionspreview_addfunction

Here’s a list of the different types of Azure Functions currently available within the Preview release. Remember, the options do vary depending on the programming language selected.

  • Empty
  • BlobTrigger
  • HttpTrigger
  • QueueTrigger
  • EventHubTrigger
  • FaceLocator
  • Generic WebHook
  • GitHub Commenter
  • GitHub WebHook
  • Http GET (CRUD)
  • Http POST (CRUD)
  • Http PUT (CRUD)
  • Image Resizer
  • ManualTrigger
  • SAS Token Generator
  • ServiceBusQueueTrigger
  • ServiceBusTopicTrigger
  • TimerTrigger

Once you choose the Azure Functions template to start from for a new Function, there are some Bindings fields that need to be filled in. These Bindings fields will vary depending on the Azure Functions template chosen to create a new Function from.

Azure Functions Project Files

vsazurefunctionspreview_solutionexplorer

The layout of the files created for a new Azure Functions project is similar to how the files of an Azure Function created through the Azure Portal are laid out.

At the root of the project are the appsettings.json and host.json files. These are files that can be used to describe some things for the projects, but at initial creation they are pretty much empty.

The appsettings.json file can be used to configure any necessary App Settings values that are needed by the Azure Functions within the project.

Then there is a folder created for each Function that gets created within the Azure Function. in this screenshot is an example of a new Azure Function that was created using the Manual Trigger C# template.

The functions.json file contains configuration data for the Function. This is the JSON file that is used to specify / configure the Function Bindings for Inputs and Outputs of the Function.

{
  "bindings": [
    {
      "type": "httpTrigger",
      "direction": "in",
      "route": "orders",
      "authLevel": "anonymous"
    },
    {
      "type": "http",
      "direction": "out"
    }
  ]
}

The project.json for a C# Azure Function is where any NuGet dependencies for the Function get defined. It’s useful to know that in addition to using the project.json file, Azure Functions to automatically have access to some standard namespace imports that just be referenced with a usingkeyword. There is also a shorthand syntax for adding references to external assemblies from within the C# script file.

Here’s a sample of a project.json file that adds a NuGet reference:

{
  "frameworks": {
    "net46":{
      "dependencies": {
        "Microsoft.ProjectOxford.Face": "1.1.0"
      }
    }
  }
}

Local Debugging

Azure Functions projects can be run on the local development machine. Currently, in the Visual Studio Tools for Azure Functions Preview release only supports remote debugging with C#, but that is expected to be expanded out in the future.

vsazurefunctionspreview_csbreakpoint

One prerequisite for running and debugging Azure Functions locally is that the Azure Functions CLI needs to be installed. The first time an Azure Functions project is run locally, it will prompt to download and install the Azure Functions CLI, so this is an easy requirement to manage / obtain.

vsazurefunctionspreview_azurefunctionscliprompt

Publishing to Azure

Azure Functions project can be published to Azure In the same manner as publishing Web Apps into an Azure Subscription. An Azure Web App is created within an Azure Subscription, then the credentials and other information for the Web App is configured within the Publish dialog for the project. Then the Azure Functions project can easily be published into Azure directly from within Visual Studio.

In line with other functionality of Azure Web Apps, the Azure Functions project can also be Debugged Remotely from the local development machine while running in Azure. Currently, this is only supported with C# based Azure Functions.

vsazurefunctionspreview_azurepublish_newwebapp

Known Limitations

The Visual Studio Tools for Azure Functions Preview announcement post lists a few known limitations for this new Preview release. The are as follows:

  • IntelliSense support is limited, and available only for C# and JavaScript by default. F#, Python and PowerShell IntelliSense support is available with the installation of additional components.
  • Adding New files is not available using “Add New Item”.
  • There is currently a bug that causes Functions published from Visual Studio to be improperly registered in Azure.
  • The C# Image Resizer function template incorrectly generates the function Bindings. These need to be manually edited to fix.

Product Feedback

The Azure Functions team is eager to get feedback from anyone using the new Visual Studio Tools for Azure Functions Preview release. Any issues can be reported using the GitHub repository (please include “Visual Studio” in the issue title), plus additional comments and questions are welcome on their Twitter accounts as well.

Chris Pietschmann is a Microsoft MVP, HashiCorp Ambassador, and Microsoft Certified Trainer (MCT) with 20+ years of experience designing and building Cloud & Enterprise systems. He has worked with companies of all sizes from startups to large enterprises. He has a passion for technology and sharing what he learns with others to help enable them to learn faster and be more productive.
Microsoft MVP HashiCorp Ambassador

Discover more from Build5Nines

Subscribe now to keep reading and get access to the full archive.

Continue reading