Book Image

.NET Standard 2.0 Cookbook

By : Fiqri Ismail
Book Image

.NET Standard 2.0 Cookbook

By: Fiqri Ismail

Overview of this book

The .NET Standard is a standard that represents a set of APIs that all .NET platforms have to implement, making it easy for developers to access and use one common library for their development needs. This book begins with a quick refresher, helping you understand the mechanics of the new standard and offering insight into how it works. You’ll explore the core library concepts, such as working with collections, configurations, I/O, security, and multithreading. You’ll explore the iOS and Android libraries of Xamarin and we’ll guide you through creating a .NET Standard 2.0 library, which you’ll use with both Android and iOS applications. In the final chapters, you’ll learn the various debugging and diagnostics tools to deliver quality libraries and create a NuGet package of the .NET Standard 2.0 library. By the end of this book, you’ll be able to expand your current workflow to various .NET flavors and have the essential skills to create a .NET Standard 2.0 library from scratch to package and deliver it to the world.
Table of Contents (18 chapters)
Title Page
Copyright and Credits
Packt Upsell
Contributors
Preface
Index

Preface

This book is a step-by-step guide to building .NET Standard 2.0 Library and its usage in various .NET platforms. Also, we will demonstrate the usage of the library using ASP.NET, ASP.NET Core, ASP.NET MVC, Xamarin iOS, and Xamarin Android. Finally, we will guide you through how to package and send your library using the NuGet package manager.

Who this book is for

This book is for developers who need to get in touch with the new .NET Standard 2.0 Library. If you have a basic knowledge of C# and what a library can do to your code, that's enough to understand this book. Also, if you are a developer who writes third-party libraries, this will give you a fair idea of what .NET Standard 2.0 Library is and how you can cater to various .NET based platforms in Windows, Linux, and macOS using it.

What this book covers

Chapter 1, Back to Basics, gives an overview of where it all began for the starters trying to build their first .NET based class library. It talks about the problems with this approach. Getting started with a simple project and using it with a console application and a classic Windows based application, the chapter talks about the issues with the current approach of libraries available. It introduces readers to .NET Standard 2.0 and its versions. How to create the first .NET Standard 2.0 library and use it with various .NET flavors such as .NET Framework and .NET Core applications is covered.

Chapter 2, Primitives, Collections, LINQ, and More, explores the Core of .NET Standard 2.0. It talks about Primitives, Collections, Reflection, and LINQ. The areas supported so far are covered. It makes use of features among different flavors of .NET Framework.

Chapter 3, Working with Files, provides an explanation of System.IO and System.Security within the .NET Standard 2.0 and the usage of read write operations using the filesystem. Also, it introduces usage in cross-platform versions of .NET Core in Ubuntu and macOS.

Chapter 4, Functional Programming, introduces functional programming capabilities in C# and how to use them in .NET Standard 2.0 Library.

Chapter 5, XML and Data, explains the usage of System.XML and System.Data within .NET Standard 2.0 for creating XML Documents and the usage of Data Tables.

Chapter 6, Exploring Threading, talks about Thread support for creating a multithreaded .NET Standard 2.0 library. This is in addition to the usage of Tasks as asynchronous capabilities of C# within the library.

Chapter 7, Networking, focuses on the usage of System.Net within .NET Standard 2.0. It dives into Sockets, Http, and Mail and how to use them in a .NET Standard Library 2.0.

Chapter 8, To iOS with Xamarin, outlines creating a simple mobile-based application using Visual Studio for Mac mobile iOS tools. The chapter guides through to create a .NET Standard 2.0 library and use it with the built iOS application.

Chapter 9, To Android with Xamarin, takes you through creating a simple mobile-based application using Visual Studio for Mac and Android tools. It showcases how to create a .NET Standard 2.0 library and use it with the built Android application.

Chapter 10, Let's Fine-Tune Our Library, demonstrates how to fine-tune .NET Standard 2.0 library using Debugging tools and Diagnostics tools. Also, it helps you capture exceptions and ensure that the end user has a solid experience using our .NET Standard Library 2.0.

Chapter 11, Packaging and Delivery, discusses how to deliver a completed .NET Standard 2.0 Library to the world. How to use NuGet package manager, creating a package, and delivering it is covered.

Chapter 12, Deploying, informs how to create a .NET Standard Library 2.0, use it with ASP.NET Core web applications, and deploy it to Azure Cloud.

To get the most out of this book

This book assumes that readers have basic knowledge of C#. Also, it assumes basic knowledge of using Visual Studio, installing packages using NuGet, and referencing libraries within projects from other projects.

Basic knowledge of using command-line tools such as bash on Ubuntu and terminal in macOS will be an added advantage but not a must.

Download the example code files

You can download the example code files for this book from your account at www.packtpub.com. If you purchased this book elsewhere, you can visit www.packtpub.com/support and register to have the files emailed directly to you.

You can download the code files by following these steps:

  1. Log in or register at www.packtpub.com.
  2. Select the SUPPORT tab.
  3. Click on Code Downloads & Errata.
  4. Enter the name of the book in the Search box and follow the onscreen instructions.

Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

  • WinRAR/7-Zip for Windows
  • Zipeg/iZip/UnRarX for Mac
  • 7-Zip/PeaZip for Linux

The code bundle for the book is also hostedon GitHub athttps://github.com/PacktPublishing/DotNET-Standard-2-Cookbook. We also have other code bundles from our rich catalog of books and videos available athttps://github.com/PacktPublishing/. Check them out!

 

Code in Action

Visit the following link to check out videos of the code being run:https://goo.gl/GwN5Xq

Conventions used

There are a number of text conventions used throughout this book.

CodeInText: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: "Mount the downloaded WebStorm-10*.dmg disk image file as another disk in your system."

A block of code is set as follows:

public void WriteLog(string message)
{
logFile.WriteLine($"{DateTime.Now} Log Message: {message} ");
}

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

if (!File.Exists(logFileName))
{
logFile = File.CreateText(logFileName);
}
else
{
logFile = File.AppendText(logFileName);
}

Any command-line input or output is written as follows:

$ dotnet build

Bold: Indicates a new term, an important word, or words that you see onscreen. For example, words in menus or dialog boxes appear in the text like this. Here is an example: "Select System info from the Administration panel."

Note

Warnings or important notes appear like this.

Note

Tips and tricks appear like this.

Sections

In this book, you will find several headings that appear frequently (Getting ready, How to do it..., How it works..., There's more..., and See also).

To give clear instructions on how to complete a recipe, use these sections as follows:

Getting ready

This section tells you what to expect in the recipe and describes how to set up any software or any preliminary settings required for the recipe.

How to do it…

This section contains the steps required to follow the recipe.

How it works…

This section usually consists of a detailed explanation of what happened in the previous section.

There's more…

This section consists of additional information about the recipe in order to make you more knowledgeable about the recipe.

See also

This section provides helpful links to other useful information for the recipe.

 

Get in touch

Feedback from our readers is always welcome.

General feedback: Email [email protected] and mention the book title in the subject of your message. If you have questions about any aspect of this book, please email us at [email protected].

Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book, we would be grateful if you would report this to us. Please visit www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details.

Piracy: If you come across any illegal copies of our works in any form on the internet, we would be grateful if you would provide us with the location address or website name. Please contact us at [email protected] with a link to the material.

If you are interested in becoming an author: If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, please visit authors.packtpub.com.

Reviews

Please leave a review. Once you have read and used this book, why not leave a review on the site that you purchased it from? Potential readers can then see and use your unbiased opinion to make purchase decisions, we at Packt can understand what you think about our products, and our authors can see your feedback on their book. Thank you!

For more information about Packt, please visit packtpub.com.