Book Image

.NET Core 2.0 By Example

By : Neha Shrivastava, Rishabh Verma
Book Image

.NET Core 2.0 By Example

By: Neha Shrivastava, Rishabh Verma

Overview of this book

With the rise in the number of tools and technologies available today, developers and architects are always exploring ways to create better and smarter solutions. Before, the differences between target platforms was a major roadblock, but that's not the case now. .NET Core 2.0 By Example will take you on an exciting journey to building better software. This book provides fresh and relevant content to .NET Core 2.0 in a succinct format that’s enjoyable to read. It also delivers concepts, along with the implications, design decisions, and potential pitfalls you might face when targeting Linux and Windows systems, in a logical and simple way. With the .NET framework at its center, the book comprises of five varied projects: a multiplayer Tic-tac-toe game; a real-time chat application, Let'sChat; a chatbot; a microservice-based buying-selling application; and a movie booking application. You will start each chapter with a high-level overview of the content, followed by the above example applications described in detail. By the end of each chapter, you will not only be proficient with the concepts, but you’ll also have created a tangible component in the application. By the end of the book, you will have built five solid projects using all the tools and support provided by the .NET Core 2.0 framework.
Table of Contents (16 chapters)
Title Page
Packt Upsell
Contributors
Preface
Index

Setting up an Ubuntu Linux VM


In this section, we will see how to set up Linux (Ubuntu) on a virtual machine, so that a Windows user can also develop and test their .NET Core 2.0 applications in Linux. To do so, let’s start with the VirtualBox setup. Oracle provides an open source VirtualBox executable, which we downloaded in the previous section. The following are the steps we need to follow to set up VirtualBox:

  1. Double-click on the VirtualBox executable. It will open a wizard. Before installation, click on Disk usage and check Disk Space Requirement. It is recommended that the virtual machine for Ubuntu Linux is set up with at least 2 GB RAM and 25 GB free hard drive space. So, instead of choosing the default drive (the C drive in our case, where Windows is installed), select another drive if it exists (for example, the D drive) so that you can easily allocate more space, and it also prevents any impact on the host operating system.
  2. The VirtualBox setup needs approximately 241 MB of disk space to install. It's recommended to create a new folder (for example, VirtualBox) to easily identify and track the VM. 
  1. Keep clicking the Next button until the last page. At the end, a warning will be displayed that the installation of VirtualBox will reset the network connection and temporarily disconnect the machine from the network. This is alright if you are working on the same physical machine. So, click on the Yes button and continue, and then click on the Install button and finish the installation:

  1. Once the preceding installation is done, open the VirtualBox manager to create a new virtual machine. Click on New and give the Name of the machine (for example, Ubuntu, as shown), and select the Type as Linux and the Version as Ubuntu (32 bit):

  1. We need to specify the memory size. More memory is good, but we should consider our disk space before selecting it. A minimum of 2 GB system memory is required for Ubuntu 17.04. Select Create and then select VDI (VirtualBox Disk Image) as Hard disk file type. Select a Dynamically allocated hard disk. It will use space on your physical hard disk as it fills up (up to the maximum fixed size). Set the disk space maximum size to 25 GB and click on Create. It will create a virtual machine with the Ubuntu operating system (32-bit) and 4 GB RAM, and the full details will be displayed on the final page:

 

Ubuntu setup using Hyper-V

For Windows machines, we can use Hyper-V to create a Linux virtual machine. Let's start with the basic settings and important configuration changes:

  1. First, enable Hyper-V Management Tools and Hyper-V Platform from Windows Features
  1. Change the default virtual directory. By default, Hyper-V uses the same drive as that on which the OS is installed but this is not a good practice. We should change the default drive the drive on which the operating system is not installed, such as the D drive in our case.  It's a good practice to keep Windows and system files separate from other files. To make configuration changes, open Hyper-V Manager and then Hyper-V Settings. Instead of the default selection, change it to some other drive (D in our case). Create a new folder named Virtual Machine on this new drive location:

   

  1. Create a virtual switch. A virtual switch is used to join computers and to create networks. We can create three types for virtual switches:
    • External: An accessible network where the virtual machines are hosted on the same physical computer and all external servers from which the host machine can connect.
    • Internal: Creates a virtual switch that can be used only by the virtual machines that run on the same physical computer, and between virtual machines and the physical computer. An internal virtual switch doesn't provide connectivity to a physical network connection.
    • Private: Creates a virtual switch that can be used only by the virtual machines that run on the same physical computer.

Create a Private or External type of virtual switch. This will be used for the virtual machine:  

Open Network and Sharing Center on your host machine and then open the external virtual switch properties. You will find Hyper-V Extensible Virtual Switch. This provides network connectivity to the virtual machine. Enable this or the virtual machine won't be able to connect to the host machine network:

  1. Create a new virtual machine, and choose the name and location for the virtual machine. Select Generation 1 on the next page and select External Virtual Switch. Select the Install an operating system from a bootable CD/DVD-ROM option and select Image file (.iso), which we downloaded earlier for Ubuntu. Continue clicking the Next button in the wizard and the Ubuntu virtual machine will be created. Click on Start and connect to it:

  1. After connection, we will be able to see the following screen. Select Install Ubuntu and set the language as English. Choose the Erase disk and install Ubuntu option and then click Continue

  1. Provide the username and password that you want and click Continue. Restart the system once the installation is done:

After restarting the virtual machine, it will display a login page. Enter the password that you provided while installing Ubuntu. On successful login, it will open the homepage, from where we can start Visual Studio Code and .NET Core 2.0 SDK installation on this Ubuntu machine.