Learn ASP.NET Core 3 Second Edition
Total Page:16
File Type:pdf, Size:1020Kb
Learn ASP.NET Core 3 Second Edition Develop modern web applications with ASP.NET Core 3, Visual Studio 2019, and Azure Kenneth Yamikani Fukizi Jason De Oliveira Michel Bruchet BIRMINGHAM - MUMBAI Learn ASP.NET Core 3 Second Edition Copyright © 2019 Packt Publishing All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews. Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the authors, nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book. Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information. Commissioning Editor: Richa Tripathi Acquisition Editor: Karan Gupta Content Development Editor: Pathikrit Roy Senior Editor: Rohit Singh Technical Editor: Gaurav Gala Copy Editor: Safis Editing Project Coordinator: Francy Puthiry Proofreader: Safis Editing Indexer: Rekha Nair Production Designer: Arvindkumar Gupta First published: December 2017 Second edition: December 2019 Production reference: 1261219 Published by Packt Publishing Ltd. Livery Place 35 Livery Street Birmingham B3 2PB, UK. ISBN 978-1-78961-013-0 www.packt.com To my beautiful wife, Eva, my lovely daughters, Amara and Annelise, and my handsome son, Josh: Thank you, guys, for enduring my long extra working hours, to the point that Annelise decided that she no longer wants to become a software programmer anymore because she doesn't like the fact that I'm always working! To my parents, Kenneth Jester Fukizi and Emily Mchepa: You did a good job. - Kenneth Yamikani Fukizi Packt.com Subscribe to our online digital library for full access to over 7,000 books and videos, as well as industry leading tools to help you plan your personal development and advance your career. For more information, please visit our website. Why subscribe? Spend less time learning and more time coding with practical eBooks and Videos from over 4,000 industry professionals Improve your learning with Skill Plans built especially for you Get a free eBook or video every month Fully searchable for easy access to vital information Copy and paste, print, and bookmark content Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.packt.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at [email protected] for more details. At www.packt.com, you can also read a collection of free technical articles, sign up for a range of free newsletters, and receive exclusive discounts and offers on Packt books and eBooks. Contributors About the authors Kenneth Yamikani Fukizi is a software engineer, solutions architect, and consultant with more than 14 years of experience. He is passionate about programming and web platforms. His experience includes working as a software engineering contractor/consultant on various projects for clients based in South Africa, Australia, the U.S.A, and Canada. Kenneth is based in Cape Town and is the founder of the AfrikanCoder™ project, on which he works on a part-time basis. Kenneth is a Microsoft Certified Trainer®, Microsoft Certified Solutions Developer®, and has other technical qualifications. He holds a bachelor's degree in computer science and a master's degree in finance and is currently pursuing a PhD in computer science. A special thanks to the team of editors at Packt whose professional help and guidance is second to none; I really enjoyed working with the team. I would like to acknowledge the authors of the first edition of this book, Jason De Oliveira and Michel Bruchet, for the tremendous and timeless job they did in the first edition. This book would have been a much bigger task without their initial contribution. Jason De Oliveira works as a CTO for MEGA International, a software company in Paris. He is an experienced manager and senior solutions architect, with high-level skills in software architecture and enterprise architecture. He loves sharing his knowledge and experience via blogs, conferences, books, articles, courses, and the coaching of co-workers in his company. He has also worked on many great technical books in English and French. He frequently collaborates with Microsoft and can often be found at the Microsoft Technology Center (MTC) in Paris. Microsoft has awarded him for over 6 years with the Microsoft Most Valuable Professional in C#/.NET award for his numerous contributions to the Microsoft community. I would like to thank my lovely wife, Orianne, and my beautiful daughters, Julia and Léonie, for supporting me in my work and for accepting long days and short nights during the week, and, sometimes, even during the weekend. My life would not be the same without them! Michel Bruchet works as an application architect for MEGA International, a software company in Paris. He has over 20 years of experience as a senior architect, working on complex projects in IT and development departments. Michel has published several publications on the internet (to be found on SlideShare, LinkedIn, and more). He has worked for big companies in France, including Sanofi, Pierre et Vacances – Center Parcs, Banque de France, BPCE, and BNP. He is also the main driving force and mastermind behind Ingenius Solution, which provides efficient e-business solutions to customers around the world. I would like to thank my family for accepting that I had to work hard and, sometimes, late into the night in my spare time to write this book! About the reviewer Alvin Ashcraft is a developer living near Philadelphia. He has spent his 23-year career building software with C#, Visual Studio, WPF, ASP.NET, and more. He has been awarded the Microsoft MVP title on nine occasions. You can read his daily links for .NET developers on his blog, Morning Dew. He works as a principal software engineer for Allscripts, building healthcare software. He has previously been employed by software companies, including Oracle. He has reviewed other titles for Packt Publishing, such as Mastering ASP.NET Core 2.0, Mastering Entity Framework Core 2.0, and Learning ASP.NET Core 2.0. I would like to thank my wonderful wife, Stelene, and our three amazing daughters for their support. They were very understanding when I was reading and reviewing these chapters in the evenings and at weekends to help deliver a useful, high-quality book for .NET developers. Packt is searching for authors like you If you're interested in becoming an author for Packt, please visit authors.packtpub.com and apply today. We have worked with thousands of developers and tech professionals, just like you, to help them share their insight with the global tech community. You can make a general application, apply for a specific hot topic that we are recruiting an author for, or submit your own idea. Table of Contents Preface 1 Section 1: Section 1: Introduction and Environment Setup Chapter 1: What Is ASP.NET Core 3? 13 The history of ASP.NET 14 ASP.NET Core 3 features 16 What is new specifically to ASP.NET Core 3? 17 Cross-platform support 19 Microservice architecture 21 Working with containers 22 Performance and scalability 22 Technology restrictions 23 Common technologies not directly found in ASP.NET Core and .NET Core 24 When to choose ASP.NET Core 3 24 Summary 25 Chapter 2: Setting Up the Environment 26 Visual Studio 2019 as a development environment 27 How to install Visual Studio 2019 Community Edition 28 First steps with Visual Studio 2019 32 Creating your first ASP.NET Core 3 application in Visual Studio 2019 36 Creating your first ASP.NET Core 3 application via the command line 41 Basic debugging with Visual Studio 2019 43 Breakpoints 45 Call stack 46 Autos, Locals, and Watch Panes 47 Visual Studio Code as a development environment 47 How to install Visual Studio Code on Linux 49 Creating your first ASP.NET Core 3 application in Visual Studio Code 52 Creating your first ASP.NET Core 3 application in Linux 54 Introduction to the C# Interactive and LINQPad tools 56 Summary 58 Chapter 3: Continuous Integration Pipeline in Azure DevOps 59 Technical requirements 60 CI, CD, and build and release pipelines 60 Using Azure DevOps for CI and CD 61 Creating a free Azure DevOps subscription and your first Azure DevOps project 62 Table of Contents Organizing your work via work items 64 Understanding the scrum process 66 Using Git as a VCS 71 Using feature branches 77 Merging changes and resolving conflicts 79 Creating an Azure DevOps build pipeline 83 Creating an Azure DevOps release pipeline 87 Summary 88 Section 2: Section 2: A Practical Demonstration of ASP.NET Core 3 Chapter 4: Basic Concepts of ASP.NET Core 3 via a Custom Application: Part 1 90 Preview of the Tic-Tac-Toe demo application 91 Building the Tic-Tac-Toe game 92 Conceiving and implementing your first Tic-Tac-Toe feature 93 Targeting different .NET Core versions in the .csproj files of your projects 97 Using the Microsoft.AspNetCore.App metapackage 98 Introduction