Working with Azure Functions in Visual Studio Code like a boss

So after a while I decided to finally check Azure Functions extensions out in Visual Studio Code. I often want to check something really quickly and being forced to open Visual Studio each time makes me furious. I must say that initially I was a bit skeptical regarding Code functionality, but it turns out to be superb. Let's check what it offers for now.

Installing

Installing the extensions is super easy. Just go to the Extensions menu and search for Azure Functions:

Once extensions is installed you can easily disable or uninstall it

For now - that's really all!

Creating a function

With Azure Functions plugin installed you should be able to see available subscriptions in the Explorer area. If not left-click on the status bar where your username is displayed and select the ones you're interested in:

Workspace with only one subscription selected

 

Installing the extension gives you some more features. Now you're able to work with a project, create a function and publish it. Let's start with a function triggered by a HTTP request. Click on "Create New Project Button":

Now you're able to select a current location or create a new one where your project will be placed. Once you're satisfied you can select a language and... that's all, your workspace is ready to start working on a function.

Empty Functions project ready to rock!

Now let's create a function. You can create in in a similar way as a project. After providing all necessary data(like a name, a type of trigger, security level), a template will be created so you can start modyfing it as you wish.

A template, very similar to the one created in Visual Studio

Running a function

You can easily start testing your function by pressing F5. It'll start runtime and you'll be given an endpoint, which you can call anytime:

Publishing a function

Publishing a function from Visual Studio Code is as easy as other tasks. Once more go to the Azure Functions workspace and select "Deploy to Function App". You'll be asked about many different parameters like a subscription, resource group or storage account. Once everything's configured wait a second(or maybe two) until a function is published. You can start using it!

Function published along with a storage account and consumption plan

Summary

In the current shape VS Code will not replace full Visual Studio(at least for me personally), but I found Azure Functions extension extremely helpful in the smaller projects, which are developed fully in Code. If I don't have to switch between IDEs, I'm more than happy. 

How to install this goddamn extensions?

Hey folks, this will be a really quick post. I've struggling with deploying my ASP.NET Core app via ARM template due to some unexpected problems. Since there's no magic "Enable .NET Core" button in Azure Portal or other App Service property, there's one thing you have to do to make yourself happy. Or maybe two. None is straightforward or intuitive.

Extension

Magically the only thing you need to run ASP.NET Core app in Azure is to install an extension:

Once you have it, your application will run without hesitation. But how to enable it via ARM template?

Use internet

To be honest I got literally no idea how to install an extension with my template. After quick search using Google I found this article. It shows a nice and quick way to deploy an application:

/
{
    "type": "siteextensions",
    "name": "AspNetCoreRuntime",
    "apiVersion": "2015-04-01",
    "location": "[resourceGroup().location]",
    "properties": {
        "version": "[parameters('aspnetcoreVersion')]"
    },
    "dependsOn": [
        "[resourceId('Microsoft.Web/Sites', parameters('siteName'))]"
    ]
}

However - for some reason this advice does not work - while deploying ARM throws an error, that AspNetCoreRuntime extension could not be found. Well, it never rains but it pours.

Use your head

I decided to stop experimenting with different approaches like:

  • using different values of version property
  • using full names as the proper value of name propety
  • installing extension using Powershell where it clearly worked

And made the one, final decision - I'll get rid of version and use(hopefully) the most recent one. Using following template:

/
{
    "type": "siteextensions",
    "name": "AspNetCoreRuntime",
    "apiVersion": "2015-04-01",
    "location": "[resourceGroup().location]",
    "dependsOn": [
        "[resourceId('Microsoft.Web/Sites', parameters('siteName'))]"
    ]
}

ARM had no problems deploying my App Service. 

I'm not sure whether you have to pass a very specific version as a value or maybe this parameter is not supported currently - all in all I was a bit dissapointed, that an article 3 months old seemed to be either outdated or incomplete. This is not how you help your community.