Building CSX files using VSTS

Azure Functions seem like a great idea to develop you microservices/APIs/gateways quickly and without too much overhead. They're scalable, can integrate with plenty of other Azure capabilities seamlessly and are really cheap. However, there's one problem when building your CI/CD pipeline - by default VSTS doesn't know how to build .funproj projects. Although it's easy to fix when building a project locally(by installing a SDK for Azure Functions), VSTS(and probably other build agents) is unable to do so and will greet you with sweet:

/
The imported project "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\AzureFunctions\Microsoft.AzureFunctions.targets" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.

The solution for this issue is pretty simple - we have to provide missing files to VSTS.

Helping VSTS

If you installed Azure Functions SDK locally you can go directly to:

/
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\AzureFunctions\

You will find all missing .props and .targets file needed to build Function Apps. Copy all file from the directory and paste them somewhere next to your project. 

The last thing needed to is to modify .funproj file so it searches for the correct file. Open your .funproj file with any text editor and find <Import Project="..." /> lines. Currently they point to Program Files (x86) directory, what causes VSTS to fail when it tries to build your project because they're unavailable for it. Just change them to something like <Import Project="..\.build\Microsoft.AzureFunctions.Props" Condition="'$(VSToolsPath)' != ''" /> and <Import Project="..\.build\Microsoft.AzureFunctions.targets" Condition="'$(VSToolsPath)' != ''" /> and push to your repository. Now when VSTS tries to run another build, it will go green again.