Home Cloud & Networking A Developer's Guide to .NET in Azure

A Developer's Guide to .NET in Azure

By Anuraj Parameswaran , Tamir Al Balkhi
books-svg-icon Book
eBook $39.99 $27.98
Print $49.99
Subscription $15.99 $10 p/m for three months
$10 p/m for first 3 months. $15.99 p/m after that. Cancel Anytime!
What do you get with a Packt Subscription?
This book & 7000+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook + Subscription?
Download this book in EPUB and PDF formats, plus a monthly download credit
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook?
Download this book in EPUB and PDF formats
Access this title in our online reader
DRM FREE - Read whenever, wherever and however you want
Online reader with customised display settings for better reading experience
What do you get with video?
Download this video in MP4 format
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with video?
Stream this video
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with Audiobook?
Download a zip folder consisting of audio files (in MP3 Format) along with supplementary PDF
What do you get with Exam Trainer?
Flashcards, Mock exams, Exam Tips, Practice Questions
Access these resources with our interactive certification platform
Mobile compatible-Practice whenever, wherever, however you want
BUY NOW $10 p/m for first 3 months. $15.99 p/m after that. Cancel Anytime!
eBook $39.99 $27.98
Print $49.99
Subscription $15.99 $10 p/m for three months
What do you get with a Packt Subscription?
This book & 7000+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook + Subscription?
Download this book in EPUB and PDF formats, plus a monthly download credit
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook?
Download this book in EPUB and PDF formats
Access this title in our online reader
DRM FREE - Read whenever, wherever and however you want
Online reader with customised display settings for better reading experience
What do you get with video?
Download this video in MP4 format
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with video?
Stream this video
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with Audiobook?
Download a zip folder consisting of audio files (in MP3 Format) along with supplementary PDF
What do you get with Exam Trainer?
Flashcards, Mock exams, Exam Tips, Practice Questions
Access these resources with our interactive certification platform
Mobile compatible-Practice whenever, wherever, however you want
  1. Free Chapter
    Chapter 1: Setting Up Your Development Environment
About this book
A Developer’s Guide to .NET in Azure helps you embark on a transformative journey through Microsoft Azure that is tailored to .NET developers. This book is a curated compendium that’ll enable you to master the creation of resilient, scalable, and highly available applications. The book is divided into four parts, with Part 1 demystifying Azure for you and emphasizing the portal's utility and seamless integration. The chapters in this section help you configure your workspace for optimal Azure synergy. You’ll then move on to Part 2, where you’ll explore serverless computing, microservices, containerization, Dapr, and Azure Kubernetes Service for scalability, and build pragmatic, cost-effective applications using Azure Functions and Container apps. Part 3 delves into data and storage, showing you how to utilize Azure Blob Storage for unstructured data, Azure SQL Database for structured data, and Azure Cosmos DB for document-oriented data. The final part teaches you about messaging and security, utilizing Azure App Configuration, Event Hubs, Service Bus, Key Vault, and Azure AD B2C for robust, secure applications. By the end of this book, you’ll have mastered Azure's responsive infrastructure for exceptional applications.
Publication date:
October 2023
Publisher
Packt
Pages
504
ISBN
9781837633012

 

Setting Up Your Development Environment

Welcome to the first chapter! This chapter will guide you through the steps to set up your development environment and create your first Azure project.

We will start by discussing how to create your Azure subscription, which is the first step in getting started with Azure development. We will provide you with a step-by-step guide on setting up your subscription, including selecting the right subscription type and configuring your account settings.

Next, we will dive into configuring your development environment. This includes setting up your machine with the software, tools, and dependencies required for Azure development. We will guide you through this process, ensuring you have a well-configured environment.

After that, we will set up your Visual Studio for success. Visual Studio is a robust integrated development environment (IDE) that provides the tools to build, test, and deploy your Azure projects. We will show you how to configure Visual Studio for Azure development, including how to set up your project templates and debugging tools.

Finally, we will walk you through creating your first project in Azure. We will provide a hands-on approach, guiding you through creating a new Azure project, setting up your project structure, and deploying your project to the cloud.

In this chapter, we will cover the following main topics:

  • Creating your Azure subscription
  • Configuring your development environment
  • Setting up your Visual Studio for success
  • Creating your first project

By the end of this chapter, you will have a solid understanding of how to create your Azure subscription, configure your development environment, set up Visual Studio for success, and create your first Azure project. So, let’s get started!

 

Creating your Azure subscription

You need an Azure subscription to work with examples in this book. In this section, you will learn about how to create an Azure subscription. Let’s get started with the steps:

  1. Open the browser, and navigate to https://azure.microsoft.com/en-in/free/.
Figure 1.1 – Create your free Azure account screen

Figure 1.1 – Create your free Azure account screen

  1. Click on the Start free button. On the second screen, you need to create an account. Click on the Create one! link.
Figure 1.2 – Azure account setup – signing in with a live account/signing up for a live account

Figure 1.2 – Azure account setup – signing in with a live account/signing up for a live account

  1. You can use either your existing email address or you can create a new email address. We are using the existing email option.
Figure 1.3 – Creating a live account – email address

Figure 1.3 – Creating a live account – email address

  1. You need to create a password for your account and complete some CAPTCHA verification to create the account. Once it is completed, you will be redirected to an Azure account creation screen.
Figure 1.4 – Azure account profile creation

Figure 1.4 – Azure account profile creation

  1. On the screen, you need to provide your personal details, contact information, and your credit card information – for verification purposes. For verification purposes, $2 from your card will be charged and it will be credited to your card within one to two days.

Once the signup is successfully completed, you will be able to see the success page as follows. From this screen, you will be able to access the Azure portal.

Figure 1.5 – Azure account creation – success page

Figure 1.5 – Azure account creation – success page

  1. Click on the Go to Azure portal button to access the Azure portal and you will be able to see a screen like this.
Figure 1.6 – Azure portal

Figure 1.6 – Azure portal

The preceding screenshot shows the Azure portal where you can create and manage resources.

  1. In the portal, you can search for resources in the middle search bar, which will help you to search for resources have you created; the available Azure services that you can create; the Marketplace, which you can use to access resources from third-party providers; and documentation on the Azure service you are looking for.
  2. In this example, I am searching for Storage since there is no storage account created. It does not show any existing resources, but the portal shows me services such as Azure Storage Account and Storage browser, and then it shows some Marketplace suggestions and finally, the documentation related to the Storage keyword.
Figure 1.7 – Searching for resources – the Azure portal

Figure 1.7 – Searching for resources – the Azure portal

  1. In the portal, after the search bar, you can see a Cloud Shell icon, which helps you execute commands in either PowerShell or Bash shell – you can use this feature to create resources using the command line.
Figure 1.8 – Cloud Shell icon – Azure portal

Figure 1.8 – Cloud Shell icon – Azure portal

  1. The Directories + Subscriptions icon will help you switch between different active directories and subscriptions.
Figure 1.9 – Directories + Subscriptions – Azure portal

Figure 1.9 – Directories + Subscriptions – Azure portal

Once you click on the button, you will be able to see all directories.

Figure 1.10 – Directories + Subscriptions page – Azure portal

Figure 1.10 – Directories + Subscriptions page – Azure portal

  1. In the portal, the notifications icon will show different notifications, such as remaining credit, resource provisioning status, and so on.
Figure 1.11 – Notifications – Azure portal

Figure 1.11 – Notifications – Azure portal

  1. Next is the settings icon, which helps you to customize the look and feel of the portal.
Figure 1.12 – Settings – Azure portal

Figure 1.12 – Settings – Azure portal

Clicking on the settings icon will take you portal settings page where we have the following options:

  • By default, it will open the Directories + Subscriptions page.
  • You can click on the Appearance + startup views menu to configure the look and feel of the portal. In this section, you can also configure the first screen in terms of what you see on it when you log in.
Figure 1.13 – Configure appearance and startup view – Azure portal

Figure 1.13 – Configure appearance and startup view – Azure portal

  • The Language + region option helps you to configure the currency format and date/time value.
Figure 1.14 - Setting up language, date, and currency format – Azure portal

Figure 1.14 - Setting up language, date, and currency format – Azure portal

  • The My information section displays your email address and helps you to subscribe to different emails from Microsoft. You will be able to Export settings, which helps to export your current Azure portal configuration as a JSON file. The Delete all settings and private dashboards option helps you to remove all the settings and dashboards created.
Figure 1.15 – My information – Azure portal

Figure 1.15 – My information – Azure portal

  • Finally, the Signing out + notifications page helps you to configure notifications and sign-out options.
Figure 1.16 – Signing out and notifications configuration – Azure portal

Figure 1.16 – Signing out and notifications configuration – Azure portal

  1. Click on the Support + troubleshooting icon to learn about the health status of different Azure services. Also, you will be able to see different links to access billing FAQs, documentation, and the technical community.
Figure 1.17 – The Support and troubleshooting option – Azure portal

Figure 1.17 – The Support and troubleshooting option – Azure portal

  1. Click on the Feedback icon to share your experience with the Azure portal.
Figure 1.18 – Send feedback – Azure portal

Figure 1.18 – Send feedback – Azure portal

  1. Click on the Show Portal Menu option to see the Azure portal menu.
Figure 1.19 – Azure portal

Figure 1.19 – Azure portal

You can customize this menu, which will help you to access different services quickly. The Azure portal comes with a Dashboard view as well. You will be able to create different dashboards and share them with your other team members.

Figure 1.20 – Azure portal

Figure 1.20 – Azure portal

  1. Click on the Dashboard button to see your private dashboard – by default, it will show as My Dashboard.
Figure 1.21 – Dashboard view – Azure portal

Figure 1.21 – Dashboard view – Azure portal

  1. You can customize the dashboard. You can click on the Edit button, and on the screen, you can remove existing widgets and add different widgets.
Figure 1.22 – Customizing the dashboard – Azure portal

Figure 1.22 – Customizing the dashboard – Azure portal

  1. Upon completing the customization, you can preview the changes, and then you will be able to save the changes by clicking on the Save button. You can share the dashboard with other users in the subscription using the Share button.
Figure 1.23 – Share dashboard – Azure portal

Figure 1.23 – Share dashboard – Azure portal

In this section, we learned about creating an Azure account and how to customize and configure the Azure portal. You will be able to create and manage different Azure resources from the Azure portal.

Creating resources in the Azure portal

Next, you will learn how to create a resource in the Azure portal:

  1. You need to click on the + Create a resource button.
Figure 1.24 – Azure portal – + Create a resource

Figure 1.24 – Azure portal – + Create a resource

  1. On the next screen, you need to choose the resource you want to create.
Figure 1.25 – Azure portal – Create a resource

Figure 1.25 – Azure portal – Create a resource

For demo purposes, I will create a resource group. It’s a container that contains related resources in an Azure solution. It is a best practice to create resources related to a project or product in the same resource group. You can search for resource group and click on the first result. Then, you will be able to see the details of the service/resource you’re about to create.

Figure 1.26 – Azure portal – new resource group

Figure 1.26 – Azure portal – new resource group

  1. Click on the Create button.
  2. On the Create a resource group screen, provide the name of the resource group – HelloWorld – set Subscription to Free Trial, and set Region to a region near your location.
Figure 1.27 – Azure portal – Create a resource group – Basics screen

Figure 1.27 – Azure portal – Create a resource group – Basics screen

  1. Click on the Review + create button to view the details of the resource you’re going to create, and then create the resource upon confirmation by clicking the button again. In the case of a resource group, you will only see the configuration values you created, but in the case of certain resources such as virtual machines or app services, you need to configure mandatory fields – then, you can click on Review + create – in such a scenario, you will be able to see the default values on this screen.

Or you can assign tags to the resource on the Tags tab. Tags are key-value pairs that act as metadata for Azure resources, which helps you to identify resources. Tags are helpful for tracking, organizing, grouping, and analyzing costs for resources. It is a best practice to add tags to your Azure resources.

Figure 1.28 – Azure portal – associating tags

Figure 1.28 – Azure portal – associating tags

  1. Upon clicking the Review + create button again, you will be able to see the details of the resources and the tags:
Figure 1.29 – Azure portal – Create a resource group confirmation screen

Figure 1.29 – Azure portal – Create a resource group confirmation screen

This screen will also help you to create an automation script. You can download the Azure Resource Management (ARM) script by clicking on the Download a template for automation link.

  1. Once you click on the Create button, Azure will create the resource group and you will get a notification.
Figure 1.30 – Azure portal – Resource created notification

Figure 1.30 – Azure portal – Resource created notification

This way, you will be able to create resources in the Azure portal. Now you have learned how to create an account and create a free trial subscription in Azure portal. You also learned about how to create resources in Azure using the Azure portal. You will be able to create resources using the Azure CLI and Azure PowerShell as well. Next, you will learn about configuring your development environment.

 

Configuring your development environment

Setting up your development environment is essential for success because it provides you with the necessary tools and resources to efficiently and effectively develop, test, and deploy your software. A properly configured development environment allows you to streamline your workflow, automate tasks, and catch errors early on in the development process. If you’re new to coding, I’m sure you’re wondering how to set up the right environment for you so that you can get coding quickly and easily. You want to be able to focus on what matters most: creating great code!

There are many different ways to do this, but here is a simple guide that will show you how to set up an IDE for .NET programming on Azure. This guide will give you a solid foundation upon which you can build your knowledge of Python and other programming languages.

If you already have an environment setup, please note we will be working through examples utilizing .NET 6.0 in this book and that needs to be installed on your machine. If you are starting from scratch, follow the instructions below to get started.

Installing .NET 6.0

Follow these steps to install .NET 6.0:

  1. Open your browser and go to this web page: https://dotnet.microsoft.com/en-us/download/dotnet. We will primarily be working in .NET 6.0 so make sure to choose the option related to the system you are using.
Figure 1.31 – .NET Download page

Figure 1.31 – .NET Download page

  1. You need to download the .NET 6.0 SDK. Once the Software Development Kit (SDK) has been downloaded, execute the downloaded executable, which will bring up the following setup screen.

In a Windows operating system, the executable will show a welcome screen as follows (see Figure 1.32) from where you can install the .NET SDK. In Windows, it will prompt for administrator access.

Figure 1.32 – .NET SDK – Windows installation

Figure 1.32 – .NET SDK – Windows installation

On Mac machines, it will show a welcome screen like this.

Figure 1.33 – .NET SDK – Mac installation

Figure 1.33 – .NET SDK – Mac installation

In Linux distributions, .NET SDK supports two types of installation – manual installation and script installation. With manual installation, we need to download the .NET SDK, execute the files, and configure paths. In script installation, we can download a .NET installation script from here: https://dot.net/v1/dotnet-install.sh. For developers or normal users, scripted installation is recommended. Once we have downloaded the script, we need to make it executable using the chmod command, and then execute the script.

Here are the bash commands to do this:

> wget https://dot.net/v1/dotnet-install.sh -O dotnet-install.sh
> chmod +x ./dotnet-install.sh
> ./dotnet-install.sh

This will install the .NET 6.0 SDK in most of the Linux distributions. You can find more details about the installation here: https://learn.microsoft.com/dotnet/core/install/linux?WT.mc_id=DT-MVP-5002040.

Now that we’ve successfully installed .NET 6.0, we can continue setting up our IDEs.

 

Setting up your local environment for Azure development

You need to set up and configure the development environment for building your applications in .NET and Azure. In this section, you will configure Visual Studio Code (VS Code) and Visual Studio. Visual Studio Code is an open source editor for building ASP.NET Core and C# applications.

Installing Visual Studio Code

Follow these steps to install Visual Studio Code:

  1. Visit the Microsoft site to download Visual Studio Code: https://visualstudio.microsoft.com/downloads/
Figure 1.34 – Visual Studio/VS Code download page

Figure 1.34 – Visual Studio/VS Code download page

  1. Based on your development machine’s operating system, download the applicable VS Code executable.

Figure 1.35 – VS Code – download page

Figure 1.35 – VS Code – download page

  1. Accept the terms and conditions and continue with the installation:
Figure 1.36 – VS Code Editor

Figure 1.36 – VS Code Editor

  1. Unlike on Windows and Mac, installing VS Code on Linux is easy – we just need to run the following command: sudo snap install --classic code. This will install VS Code on Linux. For more information on the VS Code installation, check out this page: https://code.visualstudio.com/docs/setup/linux.
  2. Click on Extensions or press the Ctrl + Shift + X shortcut keys on Windows or Cmd + Shift + X on Mac and install the following extensions:
    • Azure Tools
    • Azure CLI Tools
    • Azure Pipelines
    • Azure Kubernetes Service
    • Azure Storage Explorer
    • C# Extension

Installing Visual Studio Community 2022

Follow these steps to install Visual Studio Community Edition 2022:

  1. Visit the Microsoft site to download Visual Studio: https://visualstudio.microsoft.com/downloads/
Figure 1.37 – Visual Studio download page

Figure 1.37 – Visual Studio download page

  1. Install Azure Development and the accompanying packages for .NET development; the Visual Studio setup will prompt for different installation configurations or workloads.

Figure 1.38 – Visual Studio – installation configuration

Figure 1.38 – Visual Studio – installation configuration

  1. Sign in to the cloud account you previously created to access the Azure resources within your IDE.
Figure 1.39 – Visual Studio – first screen

Figure 1.39 – Visual Studio – first screen

In this section, you learned about installing and configuring your development environment. VS Code is a cross-platform editor for debugging applications and Visual Studio is a fully featured IDE for building and debugging applications.

Now is the time to create our first project!

 

Creating your first project

After installing all of the prerequisite software listed in step 2, under the Installing Visual Studio Community 2022 section, you should be able to begin building them without the need for any extra settings. To get things going, we’ll write a straightforward function that we’ll attempt to execute to make sure everything is set up and prepared. Start up Visual Studio 2022 Community Edition and select Create a new project to get started.

Figure 1.40 – Visual Studio – welcome screen

Figure 1.40 – Visual Studio – welcome screen

Now you can select an Azure Function from the list of choices and follow the steps to get started with the project. On the first screen, configure your new project screen. We need to set the project name, project location, and solution name. On the Additional information screen, we need to configure the framework, function trigger, and authorization level. Please see the following configuration values:

Figure 1.41 – Visual Studio – creating an Azure Functions app

Figure 1.41 – Visual Studio – creating an Azure Functions app

Project Name: FunctionApp1

Project Location: C:\USER\PROJECTFOLDER

Solution Name: FunctionApp1

Functions Worker: .NET 6.0

Function: http trigger

Authorization Level: Function

After you click the OK button, you should see a screen similar to the following screenshot (see Figure 1.42). This indicates that a new function file has been created, and some standard code has already been added as a starting point. We will discuss how to create a function and its properties in the chapter of this book specifically related to Azure Functions (Chapter 5). For now, we won’t go into too much detail.

Figure 1.42 – Azure Functions project in Visual Studio

Figure 1.42 – Azure Functions project in Visual Studio

This is how, we can create an Azure Function using Visual Studio. We can other project types such as ASP.NET Core MVC, Blazor, and ASP.NET Core Web APIs. We will explore other project types in the upcoming chapters. Visual Studio will also help us to debug, deploy, and monitor the applications in Azure.

 

Summary

Congratulations on completing your first chapter on your Azure development journey! By now, you should have a solid understanding of how to set up your development environment, configure Visual Studio for Azure development, and create your first Azure project. These skills will serve as a foundation for your future Azure development work.

Remember, Azure is a powerful cloud platform with many services and solutions. By continuing to learn about and explore Azure, you can take advantage of its many benefits, including scalability, flexibility, and cost savings.

We hope this chapter has provided you with a valuable introduction to Azure development and inspired you to continue learning and exploring the world of cloud computing. The next chapter will dive deeper into Azure services and show you how to develop applications using some core services. In the next chapter, you will learn about containers, installing Docker, and building applications with container support. So, stay tuned and keep learning!

About the Authors
  • Anuraj Parameswaran

    Anuraj Parameswaran is a seasoned IT expert with over 19 years of experience, starting in 2004, with a strong focus on Azure and .NET technologies. Currently serving as the Chief Technology Officer (CTO) of Socxo Solutions Pvt. Ltd., he has received seven prestigious Microsoft MVP awards. Anuraj actively participates in mentoring programs, delivers speeches at various events, and contributes extensively to both Microsoft and Azure communities. His commitment to sharing knowledge and embracing lifelong learning is exemplified by his involvement as a technical reviewer for Packt books.

    Browse publications by this author
  • Tamir Al Balkhi

    Tamir Al Balkhi is a technology problem solver with 15 years of experience developing innovative and effective solutions for clients across various industries, including healthcare, finance, and retail. From steering small to medium-sized business projects to overseeing large enterprise implementations, Tamir has consistently demonstrated exceptional leadership and technical prowess. As a cloud architect and Chief Technology Officer (CTO), Tamir specializes in designing and delivering best-in-class cloud solutions within the Microsoft Azure ecosystem. His agile-first mindset and commitment to a test-driven delivery approach have been instrumental in his ability to deliver projects on time, within budget, and beyond client expectations.

    Browse publications by this author
A Developer's Guide to .NET in Azure
Unlock this book and the full library FREE for 7 days
Start now