Developing Azure Functions with Visual Studio

Developing Azure Functions with Visual Studio

Microsoft is coming up with various changes to its Azure platform. In the past few updates, it has made easy for the developers to create and develop azure functions using visual studio.

In this blog, we will see how to develop and debug azure functions in visual studio.

Before we start developing, we would need the following tools:

  • Visual Studio 2017
  • Postman or any other tool used for calling REST(for HTTP triggers).

Please make sure that you have latest “Azure Functions and Web Jobs Tools” installed with Visual Studio 2017.

You can verify that by going to Tools>Extension and Updates in Visual Studio. Check if there are any updates to Azure Functions and Web Jobs Tools.

2018-04-24_15-56-05

Let start by creating a new solution and project. Go to File>New>Project and select Cloud from the category and then select Azure Functions.2018-04-24_16-05-45

In the next window, you will be asked to select the version of Azure Function you want to create. Azure Function v1 uses .NET Framework and v2 uses .NET Code Framework.

Please note that v2 is currently in preview.

Next, we need to select the type of trigger we want. Select empty if you want to create Azure function later. For this example, I am selecting  HTTP trigger.

Those whose function would need data storage can select the appropriate option from the storage account. For now, we can select None.

Access Rights defines the Authorization level for your azure function. Select Anonymous if you want no authorization for your function.

2018-04-24_16-11-47

Once done with the selection, click OK to create the project and azure function.

Once the project is created, you can find a file in solution explorer with name Function1.cs.

If you want, you can change the filename. Please do remember to change class names in the file too.

The Function1.cs file will look like below

2018-04-24_16-33-01

Run the project by pressing F5 or Debug>Start Debugging. It will open a console window emulator, which will set up the local Azure environment for the azure function.

Once the emulator fully complies, it will display all the azure functions running with the emulator. Since we have only one function, we can see only one function URL.

2018-04-24_16-37-34

Open Postman or any other tool for Rest. Use the URL provided in the emulator to trigger the function.

You can pass parameters in a body or as a query string. You need to write logic to parse them.

You can also log messages/error in the emulator by using log object.

Developing Azure function in Visual Studio gives the developer control and OOTB benefits of Visual Studio.

Few of the  benefits are:

  • The Function can be debugged for errors.
  • Various external packages can be added using NPM.
  • No need to use #r for referencing and assembly. It can be directly be referenced by “using” keyword.
  • The function can directly be published to Azure Resource.

 

Happy Coding.

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s