New Azure Functions SDK and VSTS - how to build your functions?

With recent release of Visual Studio 2017 15.3 we're given the possibility to use Azure Functions SDK, which is now fully integrated with IDE. This improves development greatly as we no longer have to maintain function.json by ourselves and are able to run function locally using in-built runtime. How about integrating new features into existing CI/CD pipeline? Well, there're some gotchas, fortunately you can easily configure things so everything runs smoothly.

Building a function project

When you create a new function project in VS you're given the options to easily add new functions with a boilerplate code. If you investigate .csproj file(last time I wrote about building Azure Functions using VSTS it was a .funproj file), you'll realize, that it differs greatly compared to legacy .csproj files:

<Project Sdk="Microsoft.NET.Sdk">
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.0" />
    <Reference Include="Microsoft.CSharp" />
    <None Update="host.json">
    <None Update="local.settings.json">

Considering new structure you can imagine, that it's going to give us some troubles. If you try to build it in VSTS, you'll get following error:

Error MSB4066: The attribute "Version" in element <PackageReference> is unrecognized.

Apparently using a default agent queue won't work here - agents don't have proper targets, which are required to build a project(if you build a project locally, you can find those targets in C:\Users\{USER}\.nuget\packages\\1.0.0\build\netstandard1.0\Microsoft.NET.Sdk.Functions.Build.targets). It'd possible to just import them and run on a default agent, still this looks like a workaround. However, there's an easier solution - during scheduling of your build you can choose a different queue:

Let's try to build our project once more...

 Error MSB4041: The default XML namespace of the project must be the MSBuild XML namespace. If the project is authored in the MSBuild 2003 format, please add xmlns="" to the <Project> element. If the project has been authored in the old 1.0 or 1.2 format, please convert it to MSBuild 2003 format.

There's still a problem - MSBuild is not able to determine what kind of XML is this. To fix this you can just modify <Project> node to following:

<Project Sdk="Microsoft.NET.Sdk" xmlns="">

Now your project should build correctly:

When working on this solution I found, that some people tried to build new Azure Functions projects using dotnet build step in VSTS - unfortunately this didn't work for me. Let me know if you found another way of integrating new version of .csproj with VSTS!

Quickly access and manage files in Azure Functions

As you may know, there's a possibility to access files used by your Azure Function and stored by it by going to Platform Features -> App Service Editor in the portal:

It allows you to quickly browse what is accessible to your function and check whether everything is okay. Additionally you can even edit files if needed. However, what is an alternative to logging to the portal and accessing Function App by a browser? Fortunately, there's another way of doing this by using Azure Storage Explorer.

Using Storage Explorer

If you don't have Storage Explorer yet, you can easily install it from this link. Once installed, you can add a storage account used by a Function App to be able to browse its files:

Click on "Add Account"

Use storage account name and key

Enter account name and key

Once you have configured new storage account, it should be accessible from the storage account browser.

Accessing files

To access files stored by a Function App you have to choose a storage account you previously added and go to File Shares - it should display a file share names exactly as your Function App, which allows you to access files from the underlying App Service. From there you can easily access, download and modify them as you wish.

Note that this functionality is available only for "newer" Functions Apps since those created some time ago, didn't link itself to a file share.