Create a .NET Core console application Part 3 – Add code to your application

Open the program.cs file to add code to your application.

notepad .\Program.cs

Edit the code to ourput the current datetime. Then save the file.

using System;

namespace myApp
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
	    Console.WriteLine("The current time is " + DateTime.Now);
        }
    }
}

Time to run your application once again!

Great work! Now go and build some .NET apps!

Create an Azure Function using Visual Studio Code Part 6 – Swap deployment slots

Okey, now with our new update added to another slot let’s finally swap this to our production.

In Azure, select your function app and deployment slots, press Swap and verify the source to destination.

Done and done! Now head over to your root function app url and verify that your deployed Azure function have swapped places.

Create an Azure Function using Visual Studio Code Part 5 – Using deployment slots

So now with the Azure Function in Azure we better update our code so it doesn’t say in our local environment.

Create a deployment slot in the Azure portal and give it a name.

Now head over to Visual Studio Code and inside the local project folder change the .cs code to read IN AZURE and save the file.

Right click and deploy to the new slot!

Jump back into Azure and select the deployment slot and fetch the url and append the text and Voila!

You’ve just pushed an new Azure Function app into a dev slot! Remove the -slot1 and you’ll see your old values.

In the final blog post we’ll swap this slot1 to the production slot.

Create an Azure Function using Visual Studio Code Part 4 – Deploy function to Azure

Now let’s upload this function to Azure to use online!

Go into the Azure extension and press on sign in to Azure.

After you have logged in press on the Deploy to function app.

Select create a new function app in Azure, create a global unique name and select a region.

Once done check if it’s complete by pressing the bell button.

Next jump into Azure and get the function URL and check out your function app in Azure!

But wait a minute, now our code is wrong! It’s in Azure right? Let’s push an update in the next blog post!

Create an Azure Function using Visual Studio Code Part 3 – Edit the code and pass a query string

Last time we had our Azure Function with C# and deployed and tested it. Let’s go into the function code and make a change and pass a query string and watch our function reply.

Go into the project folder and change the text after hello to say

"on my local environment!"

Launch the debugging again and append below to your string.

?name=DonaldDuck

There you go! Now in the next post we will deploy to Azure!

Create an Azure Function using Visual Studio Code Part 2 – Create a local Azure Function Project

Last time we installed both the Azure Function extension for Visual Studio Code and the local Azure Functions Core tools. This time we’ll create a local Azure Function and try it out!

In Visual Studio Code select the extension and create a new project and browse and create a new folder.

Select C# as language and select httptrigger as the template.

Finally give it a namespace.

Set the access level to anonymous.

Start debugging.

You’ll find the path to your Azure Function running in the console window. Visit the site and enjoy your local Azure Function!

In the next tutorial we will customize the function and change the reply by passing a query string!

Create an Azure Function using Visual Studio Code Part 1 – Download Clients

With an Azure subscription you get access to alot of free products, with a new Azure account some are free for 12 months and after that you can use more than 25 free products with a limit on the amount of traffic or other limits. Read here!

So let’s create a free Azure function that includes at the moment 1 million requests and 400,000 Gbs of resource consumption. You can read more about how to configure Azure Functions here.

Now first search in Visual Studio Code extensions for Azure Functions and install it.

Next we want to develop locally as well so let’s download and install the Azure Functions Core Tools here.

Restart Visual Studio Code and next time we will create a local Azure Function!