Setup the Development Environment
As one of the developers at Contoso, you know that setting up your development environment is an important step before starting to build your Azure IoT solution. You know that Microsoft provides a number of tools that can be used to develop and support your IoT solutions and that some decisions should be made about which tools your team will use. You will prepare a work environment that the team can use to develop your IoT solution, both on the Azure cloud side and for your local work environment.
After some discussion, your team has made the following high-level decisions about the dev environment:
- Operating System: Windows 10 will be used as the OS. Windows is used by most of your team, so it was a logical choice. You note that Azure IoT services support other operating systems (such as Mac OS and Linux), and Microsoft provides supporting documentation for those members of the team who choose one of these alternatives.
- General Coding Tools: Visual Studio Code and Azure CLI will be used as the primary coding tools. Both of these tools support extensions for IoT that leverage the Azure IoT SDKs.
- IoT Edge Tools: Docker Desktop Community and Python will be used to support custom IoT Edge module development.
In support of these decisions, you will be setting up the following environment:
- Windows 10 64-bit: Pro, Enterprise, or Education (Build 15063 or later). Including
- 4GB – 8GB system RAM (higher the better for Docker)
- Hyper-V and Containers features of Windows must be enabled.
- BIOS-level hardware virtualization support must be enabled in the BIOS settings.
Note: When setting up the development environment on a virtual machine, the VM environment must support nested virtualization - nested virtualization
- Azure CLI (current/latest)
- .NET Core 3.1.200 (or later) SDK
- VS Code (latest)
- Python 3.7 (not 3.8)
- Docker Desktop Community 126.96.36.199 (or later) set to Linux Containers
- Power BI Desktop (for data visualization)
- IoT Extensions for VS Code and Azure CLI
Note: A virtual machine has been created for this course that provides a majority of the tools specified above. The instructions below support using the prepared VM or setting up the development environment locally using your PC.
In This Lab
In this lab you will:
- Install the base tools and products that will be used during the labs in this course.
- Install the Azure IoT extensions for Azure CLI and Visual Studio Code.
- Verify your development environment setup
Exercise 1: Install Developer Tools and Products
Note: The tools and products associated with this Exercise are pre-installed on the virtual machine created for this course. Before continuing, check with your course Instructor to understand if you will be completing labs using the hosted lab VM environment or setting up the dev environment locally on your PC.
Task 1: Install .NET Core
.NET Core is a cross-platform version of .NET for building websites, services, and console apps.
To open the .NET Core download page, use the following link: .NET Download
On the .NET download page, under .NET Core, click Download .NET Core SDK.
The .NET Core SDK is used to build .NET Core apps. You will be using is to build/edit code files during the labs in this course.
If all you need to do is run an app that uses .NET Core on a Windows computer, you can install the .NET Core Runtime. In addition, preview and legacy versions of .NET Core can be installed using the link for “All .NET Core downloads…”.
On the popup menu, click Run, and then follow the on-screen instructions to complete the installation.
The installation should take less than a minute to complete. The following components will be installed:
- .NET Core SDK 3.1.100 or later
- .NET Core Runtime 3.1.100 or later
- ASP.NET Core Runtime 3.1.100 or later
- .NET Core Windows Desktop Runtime 3.1.0 or later
The following resources are available for further information:
Task 2: Install Visual Studio Code
To open the Visual Studio Code download page, click the following link: Download Visual Studio Code
Instructions for installing Visual Studio Code on Mac OS X and Linux can be found on the Visual Studio Code set up guide here. This page also includes more detailed instructions and tips for the Windows installation.
On the Download Visual Studio Code page, click Windows.
When you start the download, two things will happen: a popup dialog opens and some getting started guidance will be displayed.
On the popup dialog, to begin the setup process, click Run and then follow the on-screen instructions.
If you choose to Save the installer to your Downloads folder, you you can complete the installation by opening the folder and then double-clicking the VSCodeSetup executable.
By default, Visual Studio Code is installed in the “C:\Program Files (x86)\Microsoft VS Code” folder location (for a 64-bit machine). The setup process should only take about a minute.
Note: .NET Framework 4.5 is required for Visual Studio Code when installing on Windows. If you are using Windows 7, please ensure .NET Framework 4.5 is installed.
For detailed instructions on installing Visual Studio Code, see the Microsoft Visual Studio Code Installation Instruction guide here: https://code.visualstudio.com/Docs/editor/setup
Task 3: Install Azure CLI
Azure CLI 2.2 is a command-line tool that is designed to make scripting Azure-related tasks easier. It also enables you to flexibly query data, and it supports long-running operations as non-blocking processes.
Open your browser, and then navigate to the Azure CLI 2.2 tools download page: Install Azure CLI 2.2
You should be installing the latest version of the Azure CLI tools. If version 2.2 is not the latest version listed on this “azure-cli-latest” download page, install the more recent version.
On the Install Azure CLI 2.2 page, select the install option for your OS, and then follow the on-screen instructions to install the Azure CLI tool.
We will be providing detailed instructions for using the Azure CLI 2.2 tools during the labs in this course, but if you want more information now, see Get started with Azure CLI 2.2
Task 4: Install Python 3.7
You will be using Python 3.7 in support of IoT Edge and Docker.
In your Web browser, navigate to https://www.python.org/downloads/
Under “Looking for a specific release?”, to the right of Python 3.7.6, click Download.
On the Python 3.7.6 page, scroll down to the Files section of the page.
Under Files, select the installer file that is appropriate for your Operating System.
When prompted, select the option to run the installer
On the Install Python 3.7.6 dialog, click Add Python 3.7 to PATH.
Click Install Now.
When the “Setup was successful” page appears, click Disable path length limit.
To finish the installation process, click Close.
Task 5: Install Docker Desktop
You will be using Docker Desktop Community 188.8.131.52 (or later) set to Linux Containers during the lab that covers deploying IoT Edge modules.
In your Web browser, navigate to https://docs.docker.com/docker-for-windows/install/
The left-side navigation menu provides access to installations for additional operating systems.
Verify that your PC meets the System Requirements.
You can use Windows Settings to open the Windows Features dialog to verify that Hyper-V and Containers are enabled.
Click Download from Docker Hub
Under Docker Desktop for Windows, click Get Docker Desktop for Windows (stable).
To start the installation, click Run.
It can take a little while for the installation dialog for Docker Desktop to appear.
When the Installation Succeeded message appears, click Close.
Docker Desktop does not start automatically after installation. To start Docker Desktop, search for Docker, and select Docker Desktop in the search results. When the whale icon in the status bar stays steady, Docker Desktop is up-and-running, and is accessible from any terminal window.
Exercise 2: Install Dev Tool Extensions
The Visual Studio Code and Azure CLI tools both support extension that help developers to create their solutions more efficiently. Extensions for IoT have been developed by Microsoft that leverage the IoT SDKs and reduce development time.
Task 1: Install Visual Studio Code Extensions
Open Visual Studio Code.
On the left side of the Visual Studio Code window, click Extensions.
The Extensions button is sixth from the top. You can hover the mouse pointer over the buttons to display the button titles.
In the Visual Studio Code Extension manager, search for and then install the following Extensions:
Task 2: Install Azure CLI Extensions
Open a new command-line / terminal window.
At the command prompt, to install the Azure CLI extension for IoT, enter the following command:
az extension add --name azure-cli-iot-ext
Task 3: Verify Development Environment Setup
You should verify that the development environment has been set up successfully. Once this is complete, you will be ready to start building your IoT solutions.
Open a new command-line / terminal window.
Validate the Azure CLI installation by running the following command that will output the version information for the currently installed version of the Azure CLI.
az --versioncommand will output the version information for Azure CLI that you have installed (the
azure-cliversion number). This command also outputs the version number for all the Azure CLI modules installed, including the IoT extension. You should see output similar to the following:
azure-cli 2.2.0 command-modules-nspkg 2.0.3 core 2.2.0 nspkg 3.0.4 telemetry 1.0.4 Extensions: azure-cli-iot-ext 0.8.9
Validate the .NET Core 3.x SDK installation by running the following command that will output the version number for the currently installed version of the .NET Core SDK.
dotnet --versioncommand will output the version of the .NET Core SDK that is currently installed. This must be .NET Core 3.1 or higher.
Your development environment should be now setup!
Exercise 3: Set Up Course Lab Files and Alternative Tools
A number of the labs in this course rely on pre-built resources, such as a code project that can be used as a starting point for the lab activity. We provide access to these lab resources through the use of a GitHub project. In addition to resources that directly support the course labs (the resources contained in the GitHub project), there are tools that can be used to support learning opportunities outside the actual course. The instructions below lead you through the configuration of both these resource types.
Task 1: Download Course Lab Files
Microsoft has created a GitHub repo to provide access to lab resource files. Having these files local to the dev environment is required in some cases and convenient in many others. In this task you will be downloading and extracting the contents of the repo within your development environment.
In your Web browser, navigate to the following location: https://github.com/MicrosoftLearning/AZ-220-Microsoft-Azure-IoT-Developer
On the right side of the page, click Clone or download, and then click Download ZIP.
To save the ZIP file to your dev environment, click Save.
Once the file has been saved, click Open folder.
Right-click the saved ZIP file, and then click Extract all
Click Browse, and then navigate to folder location that is convenient to access.
To extract the files, click Extract.
Be sure to make note of where you located the files.
Task 2: Install Azure PowerShell Module
Note: The lab activities in this course do NOT have you using PowerShell, however, you may see sample code in reference documents that use PowerShell. If you want to run PowerShell code, you can use the following instructions to complete the installation steps.
Azure PowerShell is a set of cmdlets for managing Azure resources directly from the PowerShell command line. Azure PowerShell is designed to make it easy to learn and get started with, but provides powerful features for automation. Written in .NET Standard, Azure PowerShell works with PowerShell 5.1 on Windows, and PowerShell 6.x and higher on all platforms.
Warning: You can’t have both the AzureRM and Az modules installed for PowerShell 5.1 for Windows at the same time. If you need to keep AzureRM available on your system, install the Az module for PowerShell Core 6.x or later. To do this, install PowerShell Core 6.x or later and then follow these instructions in a PowerShell Core terminal.
Decide if you wish to install the Azure PowerShell module for just the current user (recommended approach) or for all users.
Launch the PowerShell terminal of your choice - if you are installing for all users you must launch an elevated PowerShell session either by either selecting run as administrator or with the sudo command on macOS or Linux.
To only install for the current user, enter the following command:
Install-Module -Name Az -AllowClobber -Scope CurrentUser
or to install for all users on a system, enter the following command:
Install-Module -Name Az -AllowClobber -Scope AllUsers
By default, the PowerShell gallery isn’t configured as a trusted repository for PowerShellGet. The first time you use the PSGallery you see the following prompt:
Untrusted repository You are installing the modules from an untrusted repository. If you trust this repository, change its InstallationPolicy value by running the Set-PSRepository cmdlet. Are you sure you want to install the modules from 'PSGallery'? [Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "N"):
Answer Yes or Yes to All to continue with the installation.
The Az module is a rollup module for the Azure PowerShell cmdlets. Installing it downloads all of the available Azure Resource Manager modules, and makes their cmdlets available for use.
Note: If the Az module is already installed, you can update to the latest version using:
Update-Module -Name Az