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

Installing .NET Core 2.0 and tools (Windows)


Now that we are done with the downloads, it's time to install. As seen in the last section on Windows, we have two options for development in Windows:

  • Visual Studio 2017 version 15.3
  • Visual Studio Code

Based on your choice, you can follow the appropriate installation steps.

Installing Visual Studio 2017 version 15.3

Double-click on the executable file downloaded for Visual Studio 2017 version 15.3 in the earlier section. This will start the installation. C# comes by default in every Visual Studio installation, so there is nothing to do for C#. Visual Studio 2017 also comes with F# support in all its editions: Community, Professional, and Enterprise. F# is an optional component though. The installer includes it as a selectable workload, or you can select it manually in the Individual components tab, under the Development activities category. Select F# language support:

Visual Studio 2017 version 15.3 comes with the .NET Core SDK. Select .NET Core cross-platform development under Workloads during the Visual Studio 2017 version 15.3 installation:

For other versions of Visual Studio, download the .NET Core 2.0 SDK from https://www.microsoft.com/net/download/core, or update Visual Studio to 2017 15.3 and select .NET Core cross-platform development under Workloads.

Installing Visual Studio Code

Install Visual Studio Code by double-clicking the Visual Studio Code setup executable from its download location. It's a simple installation for Windows. Once Visual Studio Code is installed, launch it. The following screenshot shows the user interface layout of Visual Studio Code. It follows the conventional editor style and displays files and folders you have access to on the left side and the code content in the editor on the right side. It can be roughly divided into seven sections, as shown in the following screenshot:

Let's discuss them:

  1. Menu bar: The standard menu bar for doing various operations in the editor, such as opening a file/folder, editing, viewing and installing extensions, changing themes, debugging, running and configuring tasks, and getting help.
  2. Activity bar: Groups the most commonly performed activities on the leftmost side of the editor. It lets the user switch between the views. It is customizable and lets the user choose the views to be displayed in the bar, by right-clicking on the bar and selecting/unselecting the views. The bar itself can be hidden in the same way. By default, it has five views, as shown in the following screenshot:
    • EXPLORER: This view lets your browse, open, and manage all the files and folders in your project. You can create, delete, and rename files and folders, as well as move files and folders from here. You can also open the files/folders in Terminal (Command Prompt in Windows) from here by right-clicking and selecting Open in Command Prompt. You can find the file/folder location as well from here.

    • SEARCH: This view lets you search and replace globally across your open folder.

    • SOURCE CONTROL: This lets you work with Git source control by default.

    • DEBUG: This view displays the breakpoints, variables, and call stack for debugging.

    • EXTENSIONS: This is used to install and manage extensions in Visual Studio Code.

  1. Side bar: This contains the view selected from the activity bar.
  2. Command Palette: As stated earlier, Visual Studio Code is keyboard-centric, so anyone who loves using a keyboard is going to have a great time working on Visual Studio Code. The Ctrl Shift P key combination brings up what is called a Command Palette. We can access all the functionality of Visual Studio Code from here. To make effective use of Visual Studio Code, it is highly recommended that the reader makes himself/herself well versed with the commands from the help menu item links:

  1. Editor: The editor is where the content of the file is displayed and the user can edit it. Visual Studio Code provides a feature called Split Editor (open to the side in Linux). Go to the View menu in the menu bar and select Split Editor (alternatively you can type the command Ctrl +\). This will create a new editor region, where you can edit a group of files. These regions are called editor groups. The open editors can also be seen in the Explorer view in the sidebar. Visual Studio Code allows up to three editor groups, designated as LEFT, CENTER, and RIGHT, as shown in the following screenshot:
  1. Panels: Displays the TERMINAL, OUTPUT, PROBLEMS, and DEBUG CONSOLE panes below the editor. To see it in action, go to the View menu and click any of the menu items from PROBLEMS, OUTPUT, DEBUG CONSOLE, and TERMINAL. Alternatively, you can also press their corresponding commands. We will see more on panels when we write our first application.
  2. Status Bar: Displays information about the opened project and files being edited, such as errors, warnings, current line and column number, encoding, and file type.

Now we are familiar with Visual Studio Code, its layout, and basic functionality.

Note

Go to the Help menu and explore in detail the features that Visual Studio Code offers. The Interactive Playground highlights a number of features in Visual Studio Code and also lets you interactively try them out. The Help menu also has Documentation, Introductory Videos, Tips and Tricks, which are very handy.

Remember, Visual Studio Code is an editor and therefore we need to add support for the language we want to work with through extensions. Visual Studio Code is very rich in extensions. For our example and for the purpose of learning .NET Core 2.0, we will install extensions for C# and F#, as we will be working with them.

Let's start with C#, as after a fresh install we do not have support for C# and hence there would be no IntelliSense to work with on the editor. To install C#, let's switch to Extension View and search for C#. We will choose C# for Visual Studio Code (powered by OmniSharp), as shown in the following screenshot:

Click Install and then click on Reload and Visual Studio Code will start supporting C# along with its IntelliSense.

Similarly, search F# and Install it. We will be using the Ionide-fsharp extension, as shown in the following screenshot:

With Visual Studio Code, we need to install .NET Core SDK - 2.0.0(x64) also, as Visual Studio Code doesn't install it. Double-click on the executable of .NET Core 2.0 SDK to install it, as shown in the following screenshot:

And with this, we are done with the installation of our prerequisites for development on the Windows platform. Next, we will set up a Linux (Ubuntu) VM and perform the installation of prerequisites there. If you are using a Windows platform and do not wish to set up a Linux VM, the next section can be skipped.

Note

The Visual Studio Code user interface was developed on the Electron framework, which is an open source framework used to build cross-platform desktop applications with JavaScript, HTML, and CSS. The editor is powered by Microsoft's Monaco Editor and gets its intelligence from OmniSharp/Roslyn and TypeScript. As all of these are open source, you can search them and see the source code in GitHub.