Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
vermeir_nico_introducing_net_6_getting_started_with_blazor_m.pdf
Скачиваний:
19
Добавлен:
26.06.2023
Размер:
11.64 Mб
Скачать

Introducing

.NET 6

Getting Started with Blazor, MAUI, Windows App SDK, Desktop Development,

and Containers

Nico Vermeir

Introducing .NET 6

Getting Started with Blazor, MAUI, Windows App SDK, Desktop Development, and Containers

Nico Vermeir

Introducing .NET 6: Getting Started with Blazor, MAUI, Windows App SDK, Desktop Development, and Containers

Nico Vermeir

Merchtem, Belgium

ISBN-13 (pbk): 978-1-4842-7318-0\

 

ISBN-13 (electronic): 978-1-4842-7319-7

https://doi.org/10.1007/978-1-4842-7319-7

 

Copyright © 2022 by Nico Vermeir

This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way, and transmission or information storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now known or hereafter developed.

Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark.

The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights.

While the advice and information in this book are believed to be true and accurate at the date of publication, neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or omissions that may be made. The publisher makes no warranty, express or implied, with respect to the material contained herein.

Managing Director, Apress Media LLC: Welmoed Spahr

Acquisitions Editor: Joan Murray

Development Editor: Laura Berendson

Coordinating Editor: Jill Balzano

Cover image designed by Freepik (www.freepik.com)

Distributed to the book trade worldwide by Springer Science+Business Media LLC, 1 New York Plaza, Suite 4600, New York, NY 10004. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail orders-ny@springer-sbm. com, or visit www.springeronline.com. Apress Media, LLC is a California LLC and the sole member (owner) is Springer Science + Business Media Finance Inc (SSBM Finance Inc). SSBM Finance Inc is a Delaware corporation.

For information on translations, please e-mail booktranslations@springernature.com; for reprint, paperback, or audio rights, please e-mail bookpermissions@springernature.com.

Apress titles may be purchased in bulk for academic, corporate, or promotional use. eBook versions and licenses are also available for most titles. For more information, reference our Print and eBook Bulk Sales web page at http://www.apress.com/bulk-sales.

Any source code or other supplementary material referenced by the author in this book is available to readers on GitHub via the book’s product page.

Printed on acid-free paper

Table of Contents

About the Author\ ix Acknowledgments\ xi Introduction\ xiii

Chapter 1: A Tour of .NET 6 1

.NET 6

1

Version Support

2

Supported Versions\ ...................... 3

A Unified Platform\ ........................ 4

Roadmap ...................................... 5

Supported Operating Systems\ ..... 6

Command Line Interface

8

Desktop Development\................ 12

Blazor\..........................................................................................................................................

15

MAUI ........................................... 17

Wrapping Up\ .............................. 20

Chapter 2: Runtimes and Desktop Packs 21

.NET 6 Architecture\

21

Runtimes.....................................................................................................................................

22

CoreCLR ................................ 23

Mono......................................................................................................................................

23

WinRT\....................................................................................................................................

24

Managed Execution Process\...... 24

Desktop Packs\

25

Wrapping Up\ .............................. 29

iii

Table of Contents

Chapter 3: Command Line Interface\ 31

Dotnet New\

33

Dotnet Restore\

38

NuGet.config

43

Dotnet Build\................................................................................................................................

46

Dotnet Publish

52

Dotnet Run\..................................................................................................................................

56

Dotnet Test\..................................................................................................................................

58

Using the CLI in GitHub Actions .. 60

Other Commands\

63

Wrapping Up\ .............................. 64

Chapter 4: Desktop Development\ 65

WinAPI

66

WinForms....................................................................................................................................

69

STAThread

71

WinForms Startup ................. 72

The Message Loop\

82

The Form Designer\ ............... 82

WPF ............................................ 91

WPF Startup

93

XAML Layout

95

Visual Tree\ .......................... 103

Data Binding\ ....................... 106

Windows App SDK .................... 109

Building a Windows App SDK application

110

Using Windows APIs with Windows App SDK\

113

Packaging ........................... 115

Migrating to .NET 6\

119

Upgrade Assistant\

122

Wrapping Up\ ............................ 123

iv

Table of Contents

Chapter 5: Blazor 125

Blazor WebAssembly

125

Creating a Blazor Wasm Project\

126

Blazor Progressive Web Apps\

127

Exploring the Blazor Client Project\

129

Blazor in .NET 6\ .................. 132

Blazor Component System\

134

Creating Blazor Pages\

136

Running a Blazor App\

140

Blazor Server\

144

SignalR\................................................................................................................................

144

Blazor Desktop

148

Wrapping Up\ ............................ 152

Chapter 6: MAUI 153

Project Structure

154

Exploring MAUI ......................... 156

The Cross-Platform World\

159

Application Lifecycle\

161

MVVM\........................................................................................................................................

164

MVVM Toolkit

170

Wrapping Up\ ............................ 176

Chapter 7: ASP.NET Core\ 177

Model-View-Controller\

177

Routing\................................................................................................................................

185

Views\.................................. 186

Controllers\ .......................... 189

Web API\ .................................... 200

Controller-Based APIs\

201

Minimal APIs

215

Wrapping Up\ ............................ 219

 

v

Table of Contents

Chapter 8: Microsoft Azure 221

Web Apps\

222

Creating an App Service\

222

Static Web Apps\

234

Web App for Containers\

237

Docker\ ................................ 238

Azure Functions\ ....................... 245

Deploying Azure Functions\

253

Wrapping Up\ ............................ 257

Chapter 9: Application Architecture\ 259

Record Types

259

Monolith Architecture ............... 263

Microservices

264

Container Orchestration\ ........... 265

Kubernetes\ ......................... 265

Docker Compose\ ................ 268

Dapr\..........................................................................................................................................

270

Installing Dapr\

270

Dapr State Management

272

Wrapping Up\ ............................ 273

Chapter 10: .NET Compiler Platform 275

Roslyn\

275

Compiler API\ ....................... 277

Diagnostic API ..................... 278

Scripting API\ ....................... 278

Workspace API

278

Syntax Tree\ ......................... 278

Roslyn SDK\ ......................... 279

Creating an Analyzer\

282

vi

 

Table of Contents

Source Generators\

285

Writing a Source Generator\

285

Debugging Source Generators

293

Wrapping Up\ ............................ 295

Chapter 11: Advanced .NET 6\ 297

Garbage Collector\

297

The Heap\

299

The Stack

300

Garbage Collection\

300

A Look at the Threadpool\

301

Async in .NET 6\ ........................ 304

Await/Async

304

Cancellations\ ...................... 308

WaitAsync ........................... 310

Conclusion\................................................................................................................................

311

Index 313

vii