Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
C# 8.0 and .NET Core 3.0 – Modern Cross-Platform Development

You're reading from   C# 8.0 and .NET Core 3.0 – Modern Cross-Platform Development Build applications with C#, .NET Core, Entity Framework Core, ASP.NET Core, and ML.NET using Visual Studio Code

Arrow left icon
Product type Paperback
Published in Oct 2019
Publisher Packt
ISBN-13 9781788478120
Length 818 pages
Edition 4th Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Mark J. Price Mark J. Price
Author Profile Icon Mark J. Price
Mark J. Price
Arrow right icon
View More author details
Toc

Table of Contents (21) Chapters Close

1. Hello, C#! Welcome, .NET! FREE CHAPTER 2. Speaking C# 3. Controlling Flow and Converting Types 4. Writing, Debugging, and Testing Functions 5. Building Your Own Types with Object-Oriented Programming 6. Implementing Interfaces and Inheriting Classes 7. Understanding and Packaging .NET Types 8. Working with Common .NET Types 9. Working with Files, Streams, and Serialization 10. Protecting Your Data and Applications 11. Working with Databases Using Entity Framework Core 12. Querying and Manipulating Data Using LINQ 13. Improving Performance and Scalability Using Multitasking 14. Practical Applications of C# and .NET 15. Building Websites Using ASP.NET Core Razor Pages 16. Building Websites Using the Model-View-Controller Pattern 17. Building Websites Using a Content Management System 18. Building and Consuming Web Services 19. Building Intelligent Apps Using Machine Learning 20. Building Windows Desktop Apps 21. Building Cross-Platform Mobile Apps Using Xamarin.Forms

Setting up your development environment

Before you start programming, you'll need a code editor for C#. Microsoft has a family of code editors and Integrated Development Environments (IDEs), which include:

  • Visual Studio Code
  • Visual Studio 2019
  • Visual Studio 2019 for Mac

Using Visual Studio Code for cross-platform development

The most modern and lightweight code editor to choose, and the only one from Microsoft that is cross-platform, is Microsoft Visual Studio Code. It is able to run on all common operating systems, including Windows, macOS, and many varieties of Linux, including Red Hat Enterprise Linux (RHEL) and Ubuntu.

Visual Studio Code is a good choice for modern cross-platform development because it has an extensive and growing set of extensions to support many languages beyond C#, and being cross-platform and lightweight it can be installed on all platforms that your apps will be deployed to for quick bug fixes and so on.

Using Visual Studio Code means a developer can use a cross-platform code editor to developer cross-platform apps. Therefore, I have chosen to use Visual Studio Code for all but the last two chapters for this book, because they need special features not available in Visual Studio Code for building Windows and mobile apps.

More Information: You can read about Microsoft's plans for Visual Studio Code at the following link: https://github.com/Microsoft/vscode/wiki/Roadmap.

If you prefer to use Visual Studio 2019 or Visual Studio for Mac instead of Visual Studio Code, then of course you can, but I will assume that you are already familiar with how to use them and so I will not give step-by-step instructions for using them in this book.

More Information: You can read a comparison of Visual Studio Code and Visual Studio 2019 at the following link: https://www.itworld.com/article/3403683/visual-studio-code-stepping-on-visual-studios-toes.html.

Using Visual Studio 2019 for Windows app development

Microsoft Visual Studio 2019 only runs on Windows, version 7 SP1 or later. You must run it on Windows 10 to create Universal Windows Platform (UWP) apps. It is the only Microsoft developer tool that can create Windows apps, so we will use it in Chapter 20, Building Windows Desktop Apps.

Using Visual Studio for Mac for mobile development

To create apps for the Apple operating systems like iOS to run on devices like iPhone and iPad, you must have Xcode, but that tool only runs on macOS. Although you can use Visual Studio 2019 on Windows with its Xamarin extensions to write a cross-platform mobile app, you still need macOS and Xcode to compile it.

So, we will use Visual Studio 2019 for Mac on macOS in Chapter 21, Building Cross-Platform Mobile Apps Using Xamarin.Forms.

Recommended tools for chapters

To help you to set up the best environment to use in this book, the following table summarizes which tools and operating systems I recommend be used for each of the chapters in this book:

Chapters Tool Operating systems

Chapters 1 to 19

Visual Studio Code

Windows, macOS, Linux

Chapter 20

Visual Studio 2019

Windows 10

Chapter 21

Visual Studio 2019 for Mac

macOS

To write this book, I used my MacBook Pro and the following listed software:

  • Visual Studio Code on macOS as my primary code editor.
  • Visual Studio Code on Windows 10 in a virtual machine to test OS-specific behavior like working with the filesystem.
  • Visual Studio 2019 on Windows 10 in a virtual machine to build Windows apps.
  • Visual Studio 2019 for Mac on macOS to build mobile apps.

More Information: Google and Amazon are supporters of Visual Studio Code, as you can read at the following link: https://www.cnbc.com/2018/12/20/microsoft-cmo-capossela-says-google-employees-use-visual-studio-code.html.

Deploying cross-platform

Your choice of code editor and operating system for development does not limit where your code gets deployed.

.NET Core 3.0 supports the following platforms for deployment:

  • Windows: Windows 7 SP1, or later. Windows 10 version 1607, or later. Windows Server 2012 R2 SP1, or later. Nano Server version 1803, or later.
  • Mac: macOS High Sierra (version 10.13), or later.
  • Linux: RHEL 6, or later. RHEL, CentOS, Oracle Linux version 7, or later. Ubuntu 16.04, or later. Fedora 29, or later. Debian 9, or later. openSUSE 15, or later.

More Information: You can read the official list of supported operating systems at the following link: https://github.com/dotnet/core/blob/master/release-notes/3.0/3.0-supported-os.md.

Understanding Microsoft Visual Studio Code versions

Microsoft releases a new feature version of Visual Studio Code (almost) every month and bug fix versions more frequently. For example:

  • Version 1.38, August 2019 feature release.
  • Version 1.38.1, August 2019 bug fix release.

More Information: You can read about the latest versions at the following link: https://code.visualstudio.com/updates.

The version used in this book is 1.38.1 released on 11 September 2019, but the version of Microsoft Visual Studio Code is less important than the version of the C# for Visual Studio Code extension that you will install later.

While the C# extension is not required, it provides IntelliSense as you type, code navigation, and debugging features, so it's something that's very handy to install. To support C# 8.0, you should install C# extension version 1.21.3 or later.

In this book, I will show keyboard shortcuts and screenshots of Visual Studio Code using the macOS version. Visual Studio Code on Windows and variants of Linux are practically identical, although keyboard shortcuts are likely different.

Some common keyboard shortcuts that we will use are shown in the following table:

Action macOS Windows

Show Command Palette

Cmd + Shift + P,

F1

Ctrl + Shift + P,

F1

Go To Definition

F12

F12

Go Back

Ctrl + -

Alt +

Go Forward

Ctrl + Shift + -

Alt +

Show Terminal

Ctrl + ` (backtick)

Ctrl + ' (quote)

New Terminal

Ctrl + Shift + ` (backtick)

Ctrl + Shift + ' (quote)

Toggle Line Comment

Ctrl + /

Ctrl + /

Toggle Block Comment

Shift + Option + A

Shift + Alt + A

I recommend that you download a PDF of keyboard shortcuts for your operating system from the following list:

More Information: You can learn about the default key bindings for Visual Studio Code and how to customize them at the following link: https://code.visualstudio.com/docs/getstarted/keybindings.

Visual Studio Code has rapidly improved over the past couple of years and has pleasantly surprised Microsoft with its popularity. If you are brave and like to live on the bleeding edge, then there is an Insiders edition, which is a daily build of the next version.

Downloading and installing Visual Studio Code

Now you are ready to download and install Visual Studio Code, its C# extension, and the .NET Core 3.0 SDK.

  1. Download and install either the Stable build or the Insiders edition of Visual Studio Code from the following link: https://code.visualstudio.com/.
  2. Download and install the .NET Core SDK from the following link: https://www.microsoft.com/net/download.
  3. To install the C# extension, you must first launch the Visual Studio Code application.
  4. In Visual Studio Code, click the Extensions icon or navigate to ViewExtensions.
  5. C# is one of the most popular extensions available, so you should see it at the top of the list, or you can enter C# in the search box, as shown in the following screenshot:
  1. Click Install and wait for supporting packages to download and install.

More Information: You can read more about Visual Studio Code support for C# at the following link: https://code.visualstudio.com/docs/languages/csharp.

Installing other extensions

In later chapters of this book, you will use more extensions. If you want to install them now, all the extensions that we will use are shown in the following table:

Extension Description

C# for Visual Studio Code (powered by OmniSharp)

ms-vscode.csharp

C# editing support, including syntax highlighting, IntelliSense, Go to Definition, Find All References, debugging support for .NET Core (CoreCLR), and support for project.json and csproj projects on Windows, macOS, and Linux.

C# XML Documentation Comments k--kato.docomment

Generate XML documentation comments for Visual Studio Code.

C# Extensions

jchannon.csharpextensions

Add C# class, add C# interface, add fields and properties from constructors, add constructor from properties.

REST Client

humao.rest-client

Send an HTTP request and view the response directly in Visual Studio Code.

ILSpy .NET Decompiler

icsharpcode.ilspy-vscode

Decompile MSIL assemblies – support for .NET Framework, .NET Core, and .NET Standard.

SharpPad

jmazouri.sharppad

Easily inspect the results of your code. It works similarly to standalone tools like LinqPad and RoslynPad.

You have been reading a chapter from
C# 8.0 and .NET Core 3.0 – Modern Cross-Platform Development - Fourth Edition
Published in: Oct 2019
Publisher: Packt
ISBN-13: 9781788478120
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime