Visual Studio Tools for Azure Functions

Update 5-10-2017: The first release of Visual Studio 2017 Tools for Azure Functions is now available to try. As discussed in the Visual Studio 2017 Toolspost and these 2015 tools were preview tools that provided us great feedback and learning. However, as outlined in our roadmap post, the pivot to precompiled functions with a focus on .NET Standard 2.0 means we have no plans to release any further updates to 2015 at this time. We would encourage everyone to try out the new tools for Visual Studio 2017.

Today we are pleased to announce a preview of tools for building Azure Functions for Visual Studio 2015. Azure Functions provide event-based serverless computing that make it easy to develop and scale your application, paying only for the resources your code consumes during execution. This preview offers the ability to create a function project in Visual Studio, add functions using any supported language, run them locally, and publish them to Azure. Additionally, C# functions support both local and remote debugging.

In this post, I’ll walk you through using the tools by creating a C# function, covering some important concepts along the way. Then, once we’ve seen the tools in action I’ll cover some known limitations we currently have.

For the purposes of this blog post, we’ll add an entry that speeds up the queue polling interval from the default of once a minute to once a second by setting the “maxPollingInterval” in the host.json (value is in ms)

Next, we’ll add a function to the project, by right clicking on the project in Solution Explorer, choose “Add” and then “New Azure Function”

This will bring up the New Azure Function dialog which enables us to create a function using any language supported by Azure Functions

For the purposes of this post we’ll create a “QueueTrigger – C#” function, fill in the “Queue name” field, “Storage account connection” (this is the name of the key for the setting we’ll store in “appsettings.json”), and the “Name” of our function. Note: All function types except HTTP triggers require a storage connection or you will receive an error at run time

This will create a new folder in the project with the name of our function with the following key files:

run.csx: this contains the body of the function that will be executed when triggered

The last thing we need to do in order to hook up function to our storage Queue is provide the connecting string in the appsettings.json file (in this case by setting the value of “AzureWebJobsStorage”)

Running the function locally works like any other project in Visual Studio, Ctrl + F5 starts it without debugging, and F5 (or the Start/Play button on the toolbar) launches it with debugging. Note: Debugging currently only works for C# functions. Let’s hit F5 to debug the function.

The first time we run the function, we’ll be prompted to install the Azure Functions CLI (command line) tools. Click “Yes” and wait for them to install, our function app is now running locally. We’ll see a command prompt with some messages from the Azure Functions CLI pop up, if there were any compilation problems, this is where the messages would appear since functions are dynamically compiled by the CLI tools at runtime.

We now need to manually trigger our function by pushing a message into the queue with Azure Storage Explorer. This will cause the function to execute and hit our breakpoint in Visual Studio.

Publishing to Azure

Now that we’ve tested the function locally, we’re ready to publish our function to Azure. To do this right click on the project and choose “Publish…”, then choose “Microsoft Azure App Service” as the publish target

Next, you can either pick an existing app, or create a new one. We’ll create a new one by clicking the “New…” button on the right side of the dialog

This will pop up the provisioning dialog that lets us choose or setup the Azure environment (we can customize the names or choose existing assets). These are:

Function App Name: the name of the function app, this must be unique

Subscription: the Azure subscription to use

Resource Group: what resource group the to add the Function App to

App Service Plan: What app service plan you want to run the function on. For complete information read about hosting plans, but it’s important to note that if you choose an existing App Service plan you will need to set the plan to “always on” or your functions won’t always trigger (Visual Studio automatically sets this if you create the plan from Visual Studio)

Now we’re ready to provision (create) all of the assets in Azure. Note: that the “Validate Connection” button does not work in this preview for Azure Functions

Once provisioning is complete, click “Publish” to publish the Function to Azure. We now have a publish profile which means all future publishes will skip the provisioning stepsNote: If you publish to a Consumption plan, there is currently a bug where new triggers that you define (other than HTTP) will not be registered in Azure, which can cause your functions not to trigger correctly. To work around this, open your Function App in the Azure portal and click the “Refresh” button on the lower left to fix the trigger registration. This bug with publish will be fixed on the Azure side soon.

To verify our function is working correctly in Azure, we’ll click the “Logs” button on the function’s page, and then push a message into the Queue using Storage Explorer again. We should see a message that the function successfully processed the message

The last thing to note, is that it is possible to remote debug a C# function running in Azure from Visual Studio. To do this:

Known Limitations

As previously mentioned, this is the first preview of these tools, and we have several known limitations with them. They are as follow:

IntelliSense: IntelliSense support is limited, and available only for C#, and JavaScript by default. F#, Python, and PowerShell support is available if you have installed those optional components. It is also important to note that C# and F# IntelliSense is limited at this point to classes and methods defined in the same .csx/.fsx file and a few system namespaces.

Cannot add new files using “Add New Item”: Adding new files to your function (e.g. .csx or .json files) is not available through “Add New Item”. The workaround is to add them using file explorer, the Add New File extension, or another tool such as Visual Studio Code.

Function bindings generate incorrectly when creating a C# Image Resize function: The settings for the binding “Azure Storage Blob out (imageSmall)” are overridden by the settings for the binding “Azure Storage Blob out (imageMedium)” in the generated function.json. The workaround is to go to the generated function.json and manually edit the “imageSmall” binding.

Local deployment and web deploy packages are not supported: Currently, only Web Deploy to App Service is supported. If you try to use Local Deploy or a Web Deploy Package, you’ll see the error “GatherAllFilesToPublish does not exist in the project”.

The Publish Preview shows all files in the project’s folder even if they are not part of the project: Publish preview does not function correctly, and will cause all files in the project folder to be picked up and and published. Avoid using the Preview view.

The publish option “Remove additional files at destination” does not work correctly: The workaround is to remove these files manually by going to the Azure Functions Portal, Function App Settings -> App Service Editor

Join the conversation

FYI to anyone installing this that had .NET Core projects with a project.json file, it appears that update also installs new .NET Core tooling that is possibly incompatible with project.json? After installing, my project appears to have no files, and I also get the following error:

—————————
Microsoft Visual Studio
—————————
The project system has encountered an error.

The following error occurred during discovery of project files on disk. Could not load file or assembly ‘Microsoft.VisualStudio.ProjectSystem.DotNet, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’ or one of its dependencies. The system cannot find the file specified..

A diagnostic log has been written to the following location: “C:\************\AppData\Local\Temp\VsProjectFault_2c1dba5d-03af-4e52-a40f-5e45e4400288.failure.txt”.

—————————
OK
—————————

That diagnostic file contains the following:

=====================
12/1/2016 11:33:47 AM
Recoverable
System.Exception: The following error occurred during discovery of project files on disk. Could not load file or assembly ‘Microsoft.VisualStudio.ProjectSystem.DotNet, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’ or one of its dependencies. The system cannot find the file specified..
at Microsoft.VisualStudio.ProjectSystem.DotNet.Common.FileMirroring.SourceItemsInMemoryProject.d__54.MoveNext()
— End of stack trace from previous location where exception was thrown —
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.VisualStudio.ProjectSystem.DotNet.Common.FileMirroring.SourceItemsInMemoryProject.d__52.MoveNext()
— End of stack trace from previous location where exception was thrown —
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.VisualStudio.ProjectSystem.UnconfiguredProjectImpl.AutoLoadMethodStateMachine.<b__6_0>d.MoveNext()
===================
12/1/2016 11:40:34 AM
Recoverable
System.Exception: The following error occurred during discovery of project files on disk. Could not load file or assembly ‘Microsoft.VisualStudio.ProjectSystem.DotNet, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’ or one of its dependencies. The system cannot find the file specified..
at Microsoft.VisualStudio.ProjectSystem.DotNet.Common.FileMirroring.SourceItemsInMemoryProject.d__54.MoveNext()
— End of stack trace from previous location where exception was thrown —
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.VisualStudio.ProjectSystem.DotNet.Common.FileMirroring.SourceItemsInMemoryProject.d__52.MoveNext()
— End of stack trace from previous location where exception was thrown —
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.VisualStudio.ProjectSystem.UnconfiguredProjectImpl.AutoLoadMethodStateMachine.<b__6_0>d.MoveNext()
===================

This is really causing me some pain. I have uninstalled the tooling, but I am still getting errors like the one above in Visual Studio 2015. When I open an existing .Net Core solution, I need to unload the project and reload it before it works again.

Is there any cleaning up you can recommend that the uninstall didn’t do (I manually deleted the preview3 SDK that had appeared)?

Following on from Russell’s post, i didnt remove the Azure Functions preview tooling but unloaded and then loaded the Core project. This loaded the project and i could compile and run. So it seems it’s just the initial load that’s throwing the error.

It gets worse… I have mostly got used to unloading the project and reloading it every time I open Visual Studio (albeit very annoying). But I have just tried to publish to Azure and it just sits there doing nothing. The build part completes, but the publish never starts. Cancelling the publish from the Web Publish Activity window does nothing. The only option I have is to close Visual Studio and reopen it… then unload the project and reload.

I’m at the point of uninstalling Visual Studio and reinstalling now. Not happy. Think I’ll stick to trusty Web Jobs for the foreseeable future.

Russell, thanks for your patience and sorry for all of the hassle! For the situation you’re describing with “publish to Azure”, is it the Core project where publish never starts, or the Functions project?

Btw, we’re working on allowing you to publish an assembly to Azure Functions, which will make the tooling a lot less custom.

1 year ago

Stephen Whitaker

Donna, I feel Russell’s pain! When i publish the Functions project the process starts and throws “The target GatherAllFilesToPublish does not exist in the project.” Publishing the core project does absolutely nothing.

1 year ago

Stephen Whitaker

OK – the updated package has resolved the .NET core issues. I can now publish my core app. However, the “GatherAllFilesToPublish” target is still missing when i publish my Functions app.

I’m having the same issue when attempting to create an Azure Functions type project from within Visual Studio:

The project system has encountered an error.

The following error occurred during discovery of project files on disk.
Could not load file or assembly ‘Microsoft.VisualStudio.Composition, Version=14.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’ or one of its dependencies. The located assembly’s manifest definition does not match the assembly reference. (Exception from HRESULT:0x80131040).

Thanks for these. Just what I was waiting for. Makes function so much easier with the whole flow of git to visual studio to reply.

May I ask what is the “Azure Storage Blob out (imageSmall)” you speak of? I’m looking to do a resize azure function but basedon the name of this it sounds like there is something built in or a tutorial out there where it’s done already?

@Steve, I was referring to the C# function template. There is a template to create an Azure function designed to resize an image pushed into blob storage named “Image resize – C#” that generates the template for a function designed to resize an image that is saved in blob storage

Hi team,
Thanks for the great news. Is anywhere aware of any reports that the new extension is breaking .NET Core projects in VS2015? I can’t open my project any more 🙁
Happy to grab a trace to help out resolve the issue.

So, project.json will be supported in VS 2017 when the Functions tooling is available there.

In the future, Azure Functions will likely move away from project.json, but we haven’t yet finalized the design or the timeline. It may be in a new version of the Functions runtime (2.x), for instance.

i figured it out – had to add a “bin” directory under the function just like when using the dev tools
weird that I had to add an additional dll to run it locally for microsoft.sqlserver.types that was not needed in the browser version of these c# azure function tools

Thank you for wasting my time by breaking the core projects. Honestly, “Azure Functions” is a huge joke, half-baked non-working solution again in an attempt to catch up with the rest of the world. I have a tip – don’t fall behind in the first place.

@Unhappy, we’re sorry that this initial release broke core projects in 2015, we released an update yesterday evening that fixes this issue. Beyond the Visual Studio tools which we know are not yet finished as called out above, I would love to understand what other aspects of Azure Functions you think are half-baked.

Server Error in ‘/web’ Application.
Runtime Error
Description: An exception occurred while processing your request. Additionally, another exception occurred while executing the custom error page for the first exception. The request has been terminated.

However, I am stuck at one place. Why the user name is $MyApplication… ? Do we need to create this user on Azure portal?
I am trying with the my Azure portal user, and it is giving me Unauthorized error. I am not sure what other settings we need to perform on Azure portal

@Nirman, this is currently a confusing UI as you shouldn’t need to be aware of those, but those credentials are automatically generated in Azure for publishing to consume when you provision the app. Azure creates a user name and password for tools to use, as your user credentials are issued a token that expires relatively regularly which would break some scenarios such as automated deployment from a build server on a regular basis.

Can you describe the steps you are taking that is resulting in the Unauthorized error?

@Andrew, I can confirm this same issue. I created a brand new C# Timer Trigger function. When trying to run it I get “A ScriptHost Error has occured” before eventually getting the following error: “Unable to retrieve functions list: No MediaTypeFormatter is available to read an object of type ‘FunctionEnvelope[]’ from content with media type ‘text/plain’.”

Thank you for the article. I was able to make it up to the point of publishing my function. When clicking “New” to “Create App Service” all of the dropdowns are empty. I am connected to my account, I see my email address in the upper right hand corner of the window. I can connect to my account using the “Cloud Explorer”. I see all of my plans, services and accounts there. But nothing displays when trying to create a new app service when setting up a profile for publishing.

@Chris, can you try:
-Close Visual Studio
-Navigate to %appdata%\..\Local\Microsoft\VisualStudio\14.0
-Delete the ComponentModelCache and MEFCacheBackup directories
-Start Visual Studio again

This will delete Visual Studio’s component cache and force it to rebuild it again. Will be slower when you first launch Visual Studio, but it’s possible for some reason it’s become corrupted

1 year ago

Chris

Thanks for the suggestion, but the dropdowns remain empty.

I am behind a proxy which uses a self-signed certificate in order to read encrypted traffic within the local network. Is it possible that this screen uses a different cert store than the standard machine cert store, and so an error is occurring? We have had an issue in the past where VS was not able refresh license information because of this.

We don’t currently plan to support Visual Basic scripts for Azure Functions. However, in the next couple of months we will support publishing and running .NET assemblies as the implementation of the function body, and these can be authored in Visual Basic (or any .NET language).

Is there a best practice for copying post-build DLLs of dependent class libraries into function directories? I’ve added project build dependencies so that my class libraries build along with my function project, but prior to deploying I’d like to copy the resultant DLLs into my functions project. I could create a VSTS NuGet package, but that seems like overkill when my functions project is already a member of a solution that contains its build dependencies.

Used to be able to fake this by deploying a Web App project to a Function App because it allowed a bin directory with project references. Trying to do this “right” by using the new tooling which removes that option

I’ve created a function app and run it locally. Everything works great: all the bindings, etc. However, when I right click on the project and select Publish, “Microsoft Azure App Service” is not available as an option. Only Custom and Import are visible.

Are you logged in to Azure in Cloud Explorer? If you have a regular web project, are you able to publish to App Service?

As a workaround, you can create a new Azure Function in the Azure Portal and download a publish profile:

1. Go to New -> Compute -> Azure Function App
2. Go to Function App Settings in the lower left
3. In the “Manage” section, click “Go to App Service Settings”
4. In the top toolbar, in the “…More” section, select Get Publish Profile.

Thanks for getting back to me. It hadn’t occurred to me to try with a regular web project. When I did, I also did not see Azure App Service as a target for publishing. I’ll have to look in to what might be causing this.
In the meantime, I’ve been deploying my Function App project using GitHub with the Continuous Delivery capability, and it works great. I’ll probably be staying with that for now.
If I can’t get it to work in the future, I’ll take your advice about using the generated Publish Profile.

The tooling seems great however when using the continuous deployment from Azure portal the tooling seems to break. It wants the solution as a sibling to the project file. If you move the solution down one level (or the project up one) then you no longer can debug the function in visual studio. Is there a work around for this?
Project structures
Example 1: Can’t deploy but can debug
Solution1
/FunctionA
Example 2: Can deploy but can’t debug
Solution1
FunctionA

@kapopken, can you provide more details on your project structure and how you’re doing continuous deployment (VSTS, GitHub, etc?). It might be easier if you just file a GitHub issue at https://github.com/Azure/Azure-Functions/issues so we can help troubleshoot.

I confirm the problem creating a new Functions project from Visual Studio, adding the created git repo to VSTS and then enabling continuous deployment from Functions portal. It all boils down to incompatible requirements for the directory structure.
VS creates a project in this way:
SolutionFolder
-git repo stuff
-solution file
-ProjectFolder
–host.json
–appsettings.json
–Functions folders
—Function code

When syncing this solution via git repo on VSTS, this directory structure is preserved. If I enable integration from Fx’s portal, the entire repo is downloaded into the wwwroot folder, so the structure is once again preserved. But this structure is incompatible to the way Fx host expects it to be, i.e.

@Jerry at this time we unfortunately don’t have built in tooling to automatically create a function project from an existing function. A couple of options:
–You can remote debug the existing function in Azure through Cloud Explorer
–Create an empty function project in Visual Studio, then download your existing function source using the Kudu Console view (https://github.com/projectkudu/kudu/wiki/Kudu-console) and drop the files into the function project directory.

@James, the template for a function app can be exported during create (the button to export is in the bottom left of the dialog). You can then edit the template in the json editor which has extended support for arm templates or imported into an arm template project.

Sorry, what do you mean by this? Which dialog are you talking about?
If you develop the azure function in visual studio, can you not add a web deploy package like you can do with normal websites? I tried this, but it does not provide the publish parameters.

Is it possible for the user to rename the run.csx file (if using c#)? I’ve found it a bit confusing when writing a function app with multiple functions to have several files open in the document well, all with the name “run.csx”.

How are we supposed to read those app settings when running functions locally? My appsettings.json file has several entries in the `Values` object (`AzureWebJobsStorage`, `AzureWebJobsDashboard` and `Test`) but accessing them through ConfigurationManager.AppSettings in my function does not work: ConfigurationManager.AppSettings.Count == 0. Am I missing something?

In some of my functions, I reference configured values via ConfigurationManager to get at various App Service level app settings and connection strings. Maybe I am simply overlooking something…. Is there support for this?

Taking the tooling for a spin. I have a CSharp Function and and F# Function in the same project. Hitting F5 the C# one works just fine. F# one spits out an error about binary-incompatibility of FSharp.Core.dll.

“The following 1 functions are in error:
FSharp1: Error opening binary file ‘C:\Program Files (x86)\Reference Assemblies\Microsoft\FSharp\.NETFramework\v2.0\2.3.0.0\FSharp.Core.dll’ : The referenced or default base CLI library ‘mscorlib’ is binary-incompatible with the referend F# core library ‘C:\Program Files (x86)\Reference Assemblies\Microsoft\FSharp\.NETFramework\v2.0\v2.3.0.0\FSharp.Core.dll’. Consider recompiling the library or making an explicit reference to a version of the library that matches the CLI version you are using. “

I am from China, my Azure Functions CLI(1.0.0-beta8) always downloaded failed, even I enabled VPN.
But I can install Azure Functions CLI(1.0.0-beta5) through npm with VPN.
Where can I get offline install package?

{
“frameworks”: {
“net46”:{
“dependencies”: {
“Microsoft.WindowsAzure.Storage” : “8.0.1”
}
}
}
}
====================================================
I ran into the following errors when I started an instance in CLI:

run.csx(10,5): error CS0246: The type or namespace name ‘IQuerable’ could not be found (are you missing a using directive or an assembly reference?)
Function compilation error
run.csx(10,5): error CS0246: The type or namespace name ‘IQuerable’ could not be found (are you missing a using directive or an assembly reference?)

Is deploying through VSTS currently not supported? We’re very excited about using Azure Functions but want the build process to be similar to all of our other assets. When we attempt to build through VSTS, the build fails when it reaches the Import for Microsoft.AzureFunctions.Prop in the funproj.

This is the resulting path:
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\AzureFunctions\Microsoft.AzureFunctions.Props

Hello – the experience was great except for the following (on a consumption plan with another existing Azure Function in app service):
* intellisense for referenced packages (as you know)
* deployment to Azure did not update the app settings correctly (had two settings with longer names (15+ characters). first was added but had the second’s value. The second did not add.
* the referenced nuget packages did not download until the file was remotely edited.

Is there currently an issue with the designer tools from the portal. I’ve just attempted to access an existing function app and also created a new one. The designer returns “Server Error”, 401 – Unauthorised. I’m prompted with a user name / password (very weird). I enter my azure credentials to no avail.

This works fine if i create it via the portal but with the tooling I get EventHubReader: Microsoft.Azure.WebJobs.Host: Error indexing method ‘Functions.EventHubReader’. Microsoft.WindowsAzure.Storage: Value cannot be null.
Parameter name: connectionString.

I understand this is just a preview but I am wanting to run only a specific function during development. When I debug all the functions in the FunctionsApp are in effect running. I realize that I can manually update the function.json file to disable all but the function I am working on but that feels kludgey and I worry about leaving a function disabled when I push (which is another issue).

Is there a way to debug only one function?

Is it best-practice to include the function.json in source control? In my case I pull many settings from the App Settings into my function.json so I have no problem with them being in source-control since I can control per environment via the App Settings.

I could make the function.json disabled attribute reference the App Settings and control everything from there but that again seems like a workaround rather than good form.

Another plus 1 for VS2017, but also for a timeframe on increased intellisense for both special cased imports like Newtonsoft.Json, and also for user-imported dlls. I hadn’t realised quite how lazy I’ve got, and come to depend so much on being prompted with available methods and properties.
Is there a Github repo we can report issues and track progress?
Thanks!

I’m evaluating Azure Functions to replace our EPH based Archive service which reads events from Azure IoT Hub and writes to Azure Table Storage in a certain format. I’m using EventHub Trigger binding as input, and a custom binder for Table Storage which uses DynamicTableEntity.

While the function is working fine, when run locally it is very slow in writing to Table Storage when compared to our service. I’ve observed similar delays after deploying to Azure as well. Some of the logs with duration pasted below.

I’m t-rying this out with VS 2015 community, with Azure SDK 2.9.6 installed (according to the Web PI)and installing the download. WHen I try to create a new project the Azure Functions project template doesn’t show? What might I be missing?

I installed the SDK (the Web Platform Installer installed 3.0, not 2.9.6). I go to install the Function Preview, and it says a version of the program is already installed so it exits the installer. I go into Visual Studio and the Azure Functions project is not around. *sigh*

Hi, I was using the functions projects for several weeks.
Now I had to reinstall my Computer and can’t get the function extension working again in VS2015.
The only Thing I changed knowlingly was, that I first installed VS2017, and then installed VS2015 again, to get Azure Functions Support for my existing Projects.
So I can’t use my existing projects anymore!
VS2015 tells me .funproj is unsupported application.
Any idea what to do now?

“there are no Azure Function Tools currently available for Visual Studio 2017. We are actively working on the 2017 tools, and will provide an update in the next few weeks regarding our plans and strategy.”

Why does Microsoft release an uncomplete version of Visual Studio ?!? It’s the same issue with SSDT BI tools (SSIS packages).
Each new release comes with a bunch of “to-be-released” tools and frameworks. Frustrating!

How can I add the “GoogleCloudKey” in appsettings.json in VS 2015 Azure Functions? At the web portal of azure function I just copy the complete text from the google json file into my new variable “GoogleCloudKey”. In VS2015 it doesn´t work. Why and how can I make it?

AZURE APP service version 3.0.0 seems to be included within Azure SDK now , thus installing SDK first as per the instructions is basically shooting yourself in the foot and making it impossible to install Azure app service 2.9.6 . this page needs to be updated