<<

.NET Core, UWP, NuGet

INNOVATION 2.0

■ .NET Core MicrosoftMicrosoft starts starts to to callcall it itsimply simply .NET .NET 5 5 ■ .NET Standard ■ UWP ■ NuGet Packages ■ .NET on .NET 5 - A Unified Platform

■ various tech stacks ■ .NET Framework ■ .NET Core ■ .NET ■ .NET

■ .NET 5 ■ towards one Standard ■ 5.0 Actual Version

https://appdevelopermagazine.com/looking-at-the-future-of-.net/ School of Engineering © K. Rege, ZHAW 2 von 96 … .NET 5 - A Unified Platform

■ .NET 5 is the next step towards a unified plattform ■ Produce a single .NET runtime and framework that can be used everywhere ■ Take the best of .NET Core, .NET Framework, Xamarin and Mono. ■ Build that product out of a single code-base ■ Open source and community-oriented on GitHub. ■ Cross-platform implementation ■ Side-by-side installation ■ Capable command-line interface (CLI).

School of Engineering © K. Rege, ZHAW 3 von 96 .NET Framework Evolution

■ The .NET Framework library has evolved Mono Project during the years ■ Open Source Variant of .NET ■ gestartet 2004 ■ Goal: Run .NET applications cross-platform ■ Better development tools to Linux developers. ■ Mono can be run on many platforms ■ Android, most Linux distributions, ■ BSD, macOS, Windows, Solaris, and even some game consoles such as PlayStation 3, Wii, and 360. ■ Current status ■ .NET 4.7.2 is supported ■ .NET Standard 2.1 supported .NET 1.NET 2 .NET

School of Engineering © K. Rege, ZHAW 4 von 96 Xamarin

■ Xamarin is a Microsoft owned San Francisco-based company ■ Founded in May 2011 by Mono engineers ■ Xamarin library based heavily on Mono ■ Xamarin.Forms using # and XAML that is multi platform -> XAML Flavour ■ Xamarin is a technology that allows to develop native apps for multiple platforms ■ Using a single C# codebase and .Net. ■ common code can be shared and reused, allowing to reduce the codebase . ■ Microsoft has defined a cross platform ".Net Standard" ■ but only Xamarin Forms provides portable GUIs yet https://docs.microsoft.com/en-us/xamarin/get-started/supported-platforms

School of Engineering © K. Rege, ZHAW 5 von 96 What about the UI

■ There is a different UI library on each platform

■ in the .Net Ecosystem still an issue. ■ On Windows, we find WPF (Windows Presentation Foundation) and WinForms, also for Core ■ On Linux and macOS (and also Windows) we have GtkSharp.

XAML XAML “flavors” “flavors” ■ Xamarin.Forms (XAML based) ■ iOS, Android, macOS and UWP since Core 3.0

School of Engineering © K. Rege, ZHAW 6 von 96 … What about the UI

https://docs.microsoft.com/en-us/windows/desktop/choose-your-technology

School of Engineering © K. Rege, ZHAW 7 von 96 .NET 6 Multi-platform App UI (MAUI)

■ .NET Multi-platform App UI ■ Supported with .NET 6 (LTS) ■ An evolution/replacement of Xamarin.Forms ■ Xamarin.Forms will continue to receive service releases through November 2022 ■ Xamarin XAML “flavor” in .NET MAUI. JavaJava Applets Applets ■ Cross-platform: Android, iOS, and UWP. revivedrevived ■ Suitable for reuse by other frameworks such as ■ Support in Blazor Desktop in .NET 6. ■ Full-App Themes through styling for Fluent UI and ■ Fluent Design originated by Microsoft with Win 8 (Metro) Fluent ■ Material Design originated by Google for Android (2015) ■ Rege Design originated by K. Rege for Waikiki ■ New Visual strategy ■ A combination of native controls and drawn controls

JavaJava Swing LookLook and and Feel Feel

Material waikiki School of Engineering © K. Rege, ZHAW 8 von 96 Class Library Variants (shown in VS 17)

■ Build new Class Library Project ■ .NET Framework ■ uses the full .NET 4.x Framework classes ■ .NET Core -> .NET 5 ■ uses the Core Framework classes ■ increases API surface area of your library ■ only .NET Core Apps are compatible ■ .NET Standard ■ runs on any standard compatible framework ■ such as .NET Core, .NET Framework, Mono/Xamarin ■ more Apps that will be compatible ■ decreases API surface area compatible to your library ■ Legacy Portable ■ target a specific subset of .NET implementation. ■ strongly discourage their use in new application ■ ■ To install other projects goto link below Universal Windows ■ target a very UWP specific implem. Subset ■ + the number of Apps that will be compatible ■ Native (i.e. WIN32) ■ for C++ Libraries only https://dotnet.microsoft.com/download/visual-studio-sdks?utm_source=getdotnetsdk&utm_medium=referral

School of Engineering © K. Rege, ZHAW 9 von 96 School of Engineering © K. Rege, ZHAW 10 von 96 Benefits of .NET Core

■ .NET Core (codename .NET vNext) ■ first introduced in 2014 ■ Open Source ■ The main benefits are:

School of Engineering © K. Rege, ZHAW 11 von 96 … Benefits of .NET Core

■ Compatibility: ■ .NET Core: provides a portable subset of the .NET Framework

■ Class Libraries: CoreFX ■ smaller footprint than

■ Performance and Scalability: ■ NET Core: enhance the performance and scalability due to wider platform support

■ Deployment Options: ■ .NET Framework: Internet Information only ■ .NET Core: directly in the cloud or self-host the application by creating own hosting process. ■ Framework -Dependent Deployment (FDD) ■ .NET Core SDK has to be installed on machine beforehand ■ Self-Contained Deployment (SCD) ■ .NET Core CLR and class library as part of application

School of Engineering © K. Rege, ZHAW 12 von 96 … Benefits: RyuJIT

■ New JIT Compiler (Byte Code to Machine Code) ■ more efficient native machine code ■ is 100% faster than previous version RoslinRoslin for for C# C# to to ■ generated 30% faster code BytecodeBytecode ■ supports X64 and X86 architectures

■ Profile guided optimization ■ Records information about code execution ■ This information is used for optimize code generation

■ Similar to Java's Hotspot approach but separated optimization step

School of Engineering © K. Rege, ZHAW 13 von 96 … Benefit: Designed for Microservices

■ Azure App Service ■ For stateless microservices. ■ -> Fowler GoTo 2014 Talk https://www.youtube.com/watch?v=wgdBVIX9ifA

■ Based on Docker ■ Can be hosted in your own Linux or Windows infrastructure, ■ A cloud service such as Azure Container Service.

■ Azure Service Fabric ■ for large and complex microservice systems ■ superseded by AKS

■ Azure Kubernetes Service (AKS) https://azure.microsoft.com/en-us/services/kubernetes-service/ https://docs.microsoft.com/en-us/azure/aks/

School of Engineering © K. Rege, ZHAW 14 von 96 … Benefit: Another Application Model

■ Adds Another Application Model ■ .NET Framework: for , ASP.NET, and WPF.

■ NET Core: Windows Universal Apps and ASP.NET Core

School of Engineering © K. Rege, ZHAW 15 von 96 When to Use .NET Core

■ Use .NET Core for your server application when: ■ You have cross-platform needs. ■ You are targeting microservices. ■ You are using Docker containers. ■ You need high-performance and scalable systems. ■ You need side-by-side .NET versions per application.

■ Use .NET Framework when: ■ Your App currently uses .NET Framework (recommendation is to extend instead of migrating). ■ Your App uses third-party .NET libraries or NuGet packages not available for .NET Core. ■ Your App uses .NET technologies that aren't available for .NET Core. ■ e.g. Registry,Win Forms, COM ■ Your app uses a platform that doesn’t support .NET Core.

https://docs.microsoft.com/en-us/dotnet/standard/choosing-core-framework-server

School of Engineering © K. Rege, ZHAW 16 von 96 Upgrade Path to .NET Core

School of Engineering © K. Rege, ZHAW 17 von 96 Core Hello World

School of Engineering © K. Rege, ZHAW 18 von 96 .NET Core Installation

■ Use of Version 5.0 https://dotnet.microsoft.com/download/dotnet/5.0

School of Engineering © K. Rege, ZHAW 19 von 96 Hello World Application with VS 19

> New > Project -> Console App (.NET Core)

https://docs.microsoft.com/en-us/dotnet/core/tutorials/with-visual-studio

School of Engineering © K. Rege, ZHAW 20 von 96 … Hello World Application Build and Run

■ Application template automatically defines a class, Program, with a single method, Main

■ To keep Console Window open add to generated main Method, eventually

Console.Write("PressConsole.Write("Press anyany keykey toto continue...");continue..."); Console.ReadKey(true);Console.ReadKey(true); ■ And press start

School of Engineering © K. Rege, ZHAW 21 von 96 Hello World Application with CLI

■ Simply start a new console and create a new directory, type

> dotnet --list-sdks define global.json -> default dnet-version > dotnet new globaljson --sdk-version 5.0.200 define global.json -> default dnet-version toto be be used used when when you you run run .NET .NET Core Core CLI CLI command > dotnet new console command > dotnet run Hello World! ■ Generated files Run in Command Line directly

using System; > dotnet hello.dll namespace temp { class Program { or static void Main(string[] args) { Console.WriteLine("Hello World!"); > hello.exe } } }

Exe net5.0 https://docs.microsoft.com/en-us/dotnet/standard/frameworks School of Engineering © K. Rege, ZHAW 22 von 96 Universal Windows Platform

■ A single, guaranteed (same) API Surface ■ The same on all devices

School of Engineering © K. Rege, ZHAW 23 von 96 … DOTNET CLI commands

■ CLI command structure consists of ■ the driver ("dotnet"), ■ the command (or "verb"), ■ and possibly command arguments and options.

■ Example greate, build and run

https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet?tabs=netcore21 School of Engineering © K. Rege, ZHAW 24 von 96 Development Environment

■ Visual Studio (Community Edition is free) ■ By Microsoft ■ Supported on Windows and Mac: ■ An Integrated Development Environment (IDE) for Windows and macOS. ■ Often Added ReSharper from JetBrains

■ Rider ■ By JetBrains ■ Cross-platform .NET IDE based on the IntelliJ platform and ReSharper.

■ By Microsoft and Open Source ■ Runs on Mac, Linux, and Windows ■ Based on Electron based on Chromium and Node.js ■ Integration via .NET Core command-line interface (CLI) tools

■ But also Works with any Editor such as Notepad++, Sublime, Emacs, and Vi ■ Integration via .NET Core command-line interface (CLI) tools

School of Engineering © K. Rege, ZHAW 25 von 96 Not Available for .NET 5

■ The following technologies are not (yet) available: ■ .NET Remoting ■ Application Domains ■ ASP.NET Dynamic Data ■ ASP.NET Web Forms (ASPX) ■ ASP.NET Web Services (ASMX) ■ Click-once Deployment ■ LINQ to SQL ■ Windows Communication Foundation (WCF) as Server ■ Windows Workflow Foundation (WF)

School of Engineering © K. Rege, ZHAW 26 von 96 .NET Standard

School of Engineering © K. Rege, ZHAW 27 von 96 .NET Standard

■ .NET implementations target specific versions of .NET Standard ■ an implementation advertises the highest .NET Standard version it supports ■ it also supports previous versions.

■ Goals of the .NET Standard: ■ Defines uniform set of BCL for all .NET implementations ■ Enables developers to produce portable libraries that are usable across .NET implementations. ■ Reduces or even eliminates conditional compilation of shared source due to .NET APIs ■ only required for OS specific APIs .

■ Which .NET Standard version to target ■ The higher the version, the more APIs are available to you. ■ The lower the version, the more platforms implement it.

School of Engineering © K. Rege, ZHAW 28 von 96 .NET Standard

■ Each .NET implementation version advertises the highest .NET Standard version it supports

https://github.com/dotnet/standard/blob/master/docs/versions.md https://dotnet.microsoft.com/platform/dotnet-standard

School of Engineering © K. Rege, ZHAW 29 von 96 Set Target to Standard

■ project's target framework by adding it to your project file (.csproj) https://docs.microsoft.com/en-us/dotnet/core/tutorials/libraries net5.0 ■ set to netstandard2.0 ■ And provide a runtime.config to run it hello.runtimeconfig.json { "runtimeOptions": { "tfm": "netcoreapp3.1", "framework": { "name": "Microsoft.NETCore.App", "version": "3.1.3" } } } School of Engineering © K. Rege, ZHAW 30 von 96 UWP

School of Engineering © K. Rege, ZHAW 31 von 96 One Universal Window Platform

■ UWP Goals was to unify the different Microsoft Environment

School of Engineering © K. Rege, ZHAW 32 von 96 … One Universal Window Platform

School of Engineering © K. Rege, ZHAW 33 von 96 … One Universal Window Platform

■ Goals of the Windows UWP Platform

https://docs.microsoft.com/en-us/windows/uwp/get-started/universal-application-platform-guide

School of Engineering © K. Rege, ZHAW 34 von 96 Features of UWP Apps

■ Secure: ■ UWP apps declare which device resources and data they access. ■ The user must authorize that access. ■ Able to use a common API on all devices that run . ■ Able to use device specific capabilities and adapt the UI to different device screen sizes, resolutions, and DPI. ■ Available via the ■ on all devices ■ or only those that you specify that run on Windows 10. ■ Able to be installed and uninstalled ■ without risk to the machine or incurring "machine rotten". ■ Engaging: use live tiles, push notifications, and user activities that interact with Windows Timeline and 's Pick Up Where I Left Off ■ Programmable in C#, C++, , and JavaScript. For UI, use XAML, HTML, or DirectX.

School of Engineering © K. Rege, ZHAW 35 von 96 UWP Pros and Cons

■ UWP Key Benefits ■ Store delivery ■ Isolation from other applications, better for security and stability ■ Multi Device/ARM Support such as HoloLens and IOT

■ Suffered from Microsoft’s ever-changing development strategy ■ Firstly, bringing Windows onto ARM based Tablet and Phone ■ More Secure ■ Easily deployed ■ Then UWP for Windows 10 ■ But Phone has been Canceled

■ Drawbacks ■ Users require Windows 10. ■ Designer-centric platform (like WPF) ■ Not so good for running up quick business applications -> Use Forms ■ UWP Apps behave differently from standard desktop applications https://www.itwriting.com/blog/10182-which-net-framework-for-windows-uwp-wpf-or-windows-forms.html

School of Engineering © K. Rege, ZHAW 36 von 96 Hello, World! UWP App

■ Step 1: Create a new project in Visual Studio

■ Specify Target Plattform

https://docs.microsoft.com/en-us/windows/uwp/get-started/create-a-hello-world-app-xaml-universal

School of Engineering © K. Rege, ZHAW 37 von 96 … Hello, World! UWP App

■ Click on MainPage.xaml

■ Add Controls via Toolbox; set Name if necessary

■ Double Click on Button to add Click Event Handler in Code Behind

School of Engineering © K. Rege, ZHAW 38 von 96 … Hello, World! UWP App: Run It

■ By Default Apps can only be loaded and run from Store ■ Switch to developer mode (as admin) cd C:\Windows\ImmersiveControlPanel runas /User:Administrator SystemSettings.exe

■ To publish to Store follow instructions https://docs.microsoft.com/en-us/windows/uwp/publish/

School of Engineering © K. Rege, ZHAW 39 von 96 UWP Technology

School of Engineering © K. Rege, ZHAW 40 von 96 UWP is based WinRT Technology

■ WinRT was introduced for .I.P. and Metro/Modern R.I.P. ■ WinRT as the principal system service provider (replacement for Win32 API/.NET)

■ More than 800 (COM-) objects available for approaching APIs. ■ Every object implements several interface accessed via the registry.

https://coditech.wordpress.com/2012/04/23/introduction-to-windows-runtime-and-windows-runtime-objects/ School of Engineering © K. Rege, ZHAW 41 von 96 WinRT is based on COM Mechanisms

■ WinRT object supports COM interfaces ■ Written in "native" C++ that expose APIs that are similar to the .NET Libraries ■ IUknown: parent interface ■ IInspectable: interface to inspect an object and to know what the members are

■ Compiler uses Metadata to provide the projection for the Environment

A A projection projection hides hides thethe COM COM details details

School of Engineering © K. Rege, ZHAW 42 von 96 WinRT Components are defined by MIDLs

■ Traditionally COM Objects are defined by MIDLs (Microsoft IDL) ■ these MIDLs are compiled via MIDL.EXE tool to .tlb and .h files // Example.idl import "mydefs.h","unknwn.idl"; [ object, uuid(a03d1420-b1ec-11d0-8c3a-00c04fc31d2f), ] interface IFace1 : IUnknown { HRESULT MethodA([in] short Bread, [out] BKFST * pBToast); HRESULT MethodB([in, out] BKFST * pBPoptart); }; https://docs.microsoft.com/en-us/windows/win32/com/anatomy-of-an-idl-file ■ For WinRT the Format has been simplified ■ these MIDLs (a.k.a MIDLRT) are compiled via MIDL.EXE tool to .winmd and .h files // MIDL3 Bookstore.idl namespace Bookstore { runtimeclass BookSku : Windows.UI.Xaml.Data.INotifyPropertyChanged { BookSku(); BookSku(String authorName, String coverImagePath, String title); String AuthorName{ get; }; String CoverImagePath{ get; }; String Title{ get; }; Boolean Equals(BookSku other); COMCOM has has its its own own void ApplyDiscount(Single percentOff); Type (System) } Type (System) } https://docs.microsoft.com/en-us/uwp/midl-3/intro School of Engineering © K. Rege, ZHAW 43 von 96 WinRT vs .NET Common

■ .NET and WinRT have the following features in common ■ Metadata including CLI Metadata formats ■ Namespaces ■ Classes and structs ■ Constructors ■ Static members ■ Properties ■ Collections ■ Generics ■ Enumerations ■ Delegates ■ Events ■ Async Pattern .NET 4.5 (async/await) for *async()-Methods ■ …

https://www.it-visions.de/glossar/alle/6241/Windows_Runtime.aspx

School of Engineering © K. Rege, ZHAW 44 von 96 … WinRT vs .NET Difference

■ .NET and WinRT differ in some Class Interfaces/Methods Relaxes with .NET ■ Async Operations Relaxes with .NET StandardsStandards ■ .NET returns Task ■ WinRT returns specific Types ■ e.g. PickMultipleFilesAsync() returns PickMultipleFilesOperation ■ Stucts have no Methods in WinRT ■ Some classes are named differently ■ .NET IEnumerable ■ WinRT IIterable ■ Some Members of Identically Named Classes may differ ■ Root Namespace for WinRT (instead System and Microsoft) ■ .NET System, Microsoft ■ WinRT: Windows ■ Windows.Storage.ApplicationDataContainer ■ Windows.UI.Xaml.Controls

School of Engineering © K. Rege, ZHAW 45 von 96 … WinRT vs .NET Difference: HRESULT

■ Name Description Value HRESULT S_OK Operation successful 0x00000000 ■ Operation successful but for COM functions usually return HRESULT S_FALSE returned no results 0x00000001 value E_ABORT Operation aborted 0x80004004 E_FAIL Unspecified failure 0x80004005 No such interface E_NOINTERFACE supported 0x80004002 E_NOTIMPL Not implemented 0x80004001 E_POINTER Pointer that is not valid 0x80004003 E_UNEXPECTED Unexpected failure 0x8000FFFF …

■ For .NET projection these are mapped to ■ Specific .NET Exceptions ■ Generic COMException

School of Engineering © K. Rege, ZHAW 46 von 96 UWP APIs and Capabilities

School of Engineering © K. Rege, ZHAW 47 von 96 API Reference for UWP Apps and APIs

■ Common API that you can use to deliver Apps ■ All devices that run Windows 10 https://docs.microsoft.com/en-us/uwp/

A (hell) Lot of APIs

School of Engineering © K. Rege, ZHAW 48 von 96 Platform Extensions

■ Some APIs are group in Device Families

School of Engineering © K. Rege, ZHAW 49 von 96 Capabilities Configuration

■ Are configured via e.g. Visual Studio

■ are stored in the *.apps.manifest File ,,,,

School of Engineering © K. Rege, ZHAW 50 von 96 Test Capabilities at Runtime

School of Engineering © K. Rege, ZHAW 51 von 96 Deployment of UWP Local for Tests

School of Engineering © K. Rege, ZHAW 52 von 96 Create Self Signed Certificate with PS

■ Determine the subject i.e. Publisher of your app (in .manifest)

New-SelfSignedCertificate -Type Custom -Subject "CN=Karl Rege" -KeyUsage DigitalSignature -FriendlyName "Your friendly name goes here" -CertStoreLocation "Cert:\CurrentUser\My" -TextExtension @("2.5.29.37={text}1.3.6.1.5.5.7.3.3", "2.5.29.19={text}") ■ Get the thumbprint of the generated certificate Set-Location Cert:\CurrentUser\My Get-ChildItem | Format-Table Subject, Thumbprint ■ Use that Thumbprint to export the certificate as pfx File

$password = ConvertTo-SecureString -String -Force -AsPlainText

Export-PfxCertificate -cert "Cert:\CurrentUser\My\" -FilePath .pfx -Password $password https://docs.microsoft.com/en-us/windows/msix/package/create-certificate-package-signing

School of Engineering © K. Rege, ZHAW 53 von 96 Package an UWP App

■ In Solution Explorer publish -> Create Add Package

if ifdisabled disabled no no installer installer locationlocation has has to to be be providedprovided

select generated .pfx file select generated .pfx file

School of Engineering © K. Rege, ZHAW 54 von 96 Select Output and Update Location

■ Set the Output Locatation

■ Installer Location may be a shared directory via UNC Path

onlyonly if ifautomatic automatic updates updates requiredrequired

School of Engineering © K. Rege, ZHAW 55 von 96 Trust the Application Certificate

■ A cer File is generated that can be imported to the Local Machine Cert Store

School of Engineering © K. Rege, ZHAW 56 von 96 .NET Native Compilation

■ By default, debug and test builds are compiled to IL ■ By default, release builds are compiled by using the .NET Native pre-compilation technology

■ .NET Native offers significantly faster startup times and superior performance when compared to an Apps compiled to IL

■ However, not all IL can be compiled to native code

■ Not suited for Native Compilation ■ reflection and serialization ■ type instantiation and method construction methods: ■ Type.MakeGenericType , Array.CreateInstance and Type.MakeArrayType methods

https://docs.microsoft.com/en-us/dotnet/framework/net-native/getting-started-with-net-native

School of Engineering © K. Rege, ZHAW 57 von 96 Start the App

■ Get App Installer App (if necessary)

■ Double Click on Bundle or App Installer

School of Engineering © K. Rege, ZHAW 58 von 96 Design Considerations of UWP Apps

School of Engineering © K. Rege, ZHAW 59 von 96 GUI design for UWP https://docs.microsoft.com/en-us/windows/uwp/design/basics/design-and-ui-intro

Effective Pixels Size and Scaling ■ System normalize the way UI elements display on the screen ■ Taking account viewing distance and screen density ■ The scaling algorithm ensures that a 24 px font on 10 feet away is just as legible to the user as a 24 px font on 5"

■ UWP scales across a range of devices with scaling plateaus of ■ 100%, 125%, 150%, 175%, 200%, 225%, 250%, 300%, 350%, and 400%. ■ However: ■ W10 scaling is different than previous OSs to support also smaller mobile devices ■ Automatic Scaling may result in blurry fonts and/or icons ■ Principle Question: Application or OS Scaling for High DPI ■ Older Programs may not be "High DPI" aware resulting in unusable small Icons,Buttons ■ e.g. Adobe see:http://www.danantonielli.com/adobe-app-scaling-on-high-dpi-displays-fix/

School of Engineering © K. Rege, ZHAW 60 von 96 … GUI design for UWP

Page Layout ■ Most pages follow a common structure to provide consistency ■ users can easily navigate between and within pages of your app. ■ Pages typically contain three types of UI elements: ■ Navigation elements help users choose the content they want to display. ■ Command elements initiate actions, such as manipulating, saving, or sharing content. ■ Content elements display the app's content.

■ The arrangement of the UI elements may differ for e.g. small mobile devices https://docs.microsoft.com/en-us/windows/uwp/design/layout/page-layout School of Engineering © K. Rege, ZHAW 61 von 96 … GUI design for UWP

Adaptive Layouts ■ Different Layouts according physical dimensions ■ 1. Define so called " points" when different layout should be triggered 0 641 all size 0 .. 640 1008 ■ 2. Define the Triggers for these layouts

School of Engineering © K. Rege, ZHAW 62 von 96 … GUI design for UWP

■ 3. Define Properties of this Layout by Setters

...

...

■ -> see WPF lecture "Styles"

School of Engineering © K. Rege, ZHAW 63 von 96 … GUI design for UWP

■ Color ■ Use color meaningfully ■ Color is personal ■ indicate interactivity ■ Color is cultural ■ Color merely as additional criterion 8% are partially color blind (red-green) ■ Typograph ■ default font for UWP apps -> UI

■ Icons ■ Use predefined icons when possible ■ Segoe MDL2 Assets font or SVG ■ no Bitmaps ■ XAML Theme Resources are tailored for the "Light" and "Dark" themes

School of Engineering © K. Rege, ZHAW 64 von 96 … GUI design for UWP

Common Controls ■ a set that are guaranteed to work well on all Windows-powered devices

https://docs.microsoft.com/en-us/windows/uwp/design/fluent-design-system/index School of Engineering © K. Rege, ZHAW 65 von 96 NuGet Packa ges

School of Engineering © K. Rege, ZHAW 66 von 96 NuGet

■ NuGet, the open source ; it's goals are ■ Share functionality between projects ■ Publish packages ■ Improve and automate parts of the development process ■ Versioning of packages

■ Tooling ■ Visual Studio extension ■ Standalone Console Program

■ Server ■ Publicly available package servers such as .org . ■ Microsoft itself uses NuGet extensively for the provision of components ■ Many Visual Studio project templates include references to NuGet packages ■ Even parts of the .NET Framework itself are now shipped via NuGet packages

https://entwickler.de/online/paeckchen-packen-mit-nuget-und-tfs-159983.html

School of Engineering © K. Rege, ZHAW 67 von 96 NuGet - Installation

■ Installed with VS 2019 in ■ C:\Program Files\\Editor\Data\Tools -> Add to Path if CLI used

■ Or get it online (Windows) ■ https://www.nuget.org/downloads

■ Other Platforms (Linux/Mac) ■ https://docs.microsoft.com/en-us/nuget/tools/nuget-exe-cli-reference

School of Engineering © K. Rege, ZHAW 68 von 96 Consumption of a NuGet Package

School of Engineering © K. Rege, ZHAW 69 von 96 Use of NuGet packages

■ The package management is divided into different areas: ■ Browse: ■ All packages that are available for installation are displayed here. ■ Section is divided into different package servers.

■ Installed: ■ All packages that are already installed ■ Incidentally, the packages can also be uninstalled in this section.

■ Updates: ■ Displays packages that are already installed and available for updates.

■ Tools -> Options ■ other alternative sources such as myget.org ■ or your own local sources

School of Engineering © K. Rege, ZHAW 70 von 96 … Use of NuGet packages in VS

■ Package Manager UI ■ Solution Explorer, right-click References and choose Manage NuGet Packages.

■ Choose "nuget.org" as the Package source, select the Browse tab, search for e.g. Newtonsoft.Json, select that package in the list, and select Install:

■ Accept any license prompts.

■ If prompted to select a package management format, select PackageReference in project file:

https://docs.microsoft.com/en-us/nuget/quickstart/install-and-use-a-package-in-visual-studio

School of Engineering © K. Rege, ZHAW 71 von 96 … Use of NuGet packages Files Generated

■ NuGet automatically creates a file named packages.config within the project

■ or for core in the .csproj File add a ItemGroup section .... ■ The packages are then downloaded automatically (restore) and stored locally ■ In addition, ■ it is possible to manipulate configuration files and insert additional entries ■ Another advantage is that dependencies to other packages can be defined ■ when installing a package these dependencies are detected and the corresponding packages are automatically installed.

School of Engineering © K. Rege, ZHAW 72 von 96 Versioning/Updating of Packages

■ Advantages of using NuGet is that the Package Manager comes with a versioning and updating mechanism.

■ The reference in the project is always set by NuGet to the version specified in the packages.config

■ The Package Manager displays all packages for which there is a newer version. ■ These can be updated accordingly from there. ■ The new version of the package is then downloaded to the packages folder and the reference to the new version is changed.

■ Also dependencies and missing packages are added automatically

School of Engineering © K. Rege, ZHAW 73 von 96 Package Manager CLI

■ Select the VS Tools > NuGet Package Manager > Package Manager Console menu command. ■ Check that the Default project drop- down list shows the project into which you want to install the package. ■ If you have a single project in the solution, it is already selected.

■ a Newtonsoft.Json.12.0.1 directory Enter the command Install-Package e.g. a Newtonsoft.Json.12.0.1 directory will be created with the .nupkg Newtonsoft.Json (see Install-Package). will be created with the .nupkg ■ Errors typically indicate that the package isn't cd \your_project_folder\ compatible with the project's target framework. nuget.exe Install Newtonsoft.Json -Version 12.0.1 ■ The CLI nuget install command does not modify project files or the packages.config file ■ Entries must be managed manually.

School of Engineering © K. Rege, ZHAW 74 von 96 Creation of a NuGet Package

School of Engineering © K. Rege, ZHAW 75 von 96 Create a package using VS

■ Create a class library project ■ Configure package properties ■ Project > Properties menu command, then select the Package tab ■ Give your package a unique identifier and fill out any other desired properties. ■ For a description of the different properties, see .nuspec file reference. All of the properties here go into the .nuspec manifest that Visual Studio creates for the project.

https://docs.microsoft.com/en-us/nuget/quickstart/create-and-publish-a-package-using-visual-studio

School of Engineering © K. Rege, ZHAW 76 von 96 … Create a package using VS

■ Set the configuration to Release. ■ Right click the project in Solution Explorer and select the Pack command:

■ Visual Studio builds the project and creates the .nupkg file.

School of Engineering © K. Rege, ZHAW 77 von 96 Create a package using CLI

Creating a .nuspec File in your project folder errlog.io 1.1.18 … …

■ add Picture is worth a thousand pull requests If your library uses any If your library uses any ■ Including a README.MD file packages, packages, ■ build your NuGet package cd \your_project_folder\ nuget.exe config -Set repositoryPath="\full-path-to-your-packages-folder\" nuget.exe pack -IncludeReferencedProjects -properties Configuration=Release

School of Engineering © K. Rege, ZHAW 78 von 96 …. Create a package using CLI

■ .Nuspec Example errlog.io 1.1.18 ErrLog.IO Error and Exception Logging Tool Matthew Proctor, Michael Sanders, Alastair Bateman kutamo https://errlog.io/terms https://errlog.io/docs/getting-started https://www.errlog.io/images/errlog_dark_logo.png false ErrLog.IO is an exception and error logging tool Bug fixes and performance improvements Copyright 2017 Kutamo Pty. Ltd. exceptions web http error logging

ErrLog.IO is an exception and error logging tool. stepstep by by step step tutorials tutorials https://www.wiliam.com.au/wiliam-blog/creating-a-nuget-package https://www.errlog.io/blogs/2017/12/creating-a-nuget-package

School of Engineering © K. Rege, ZHAW 79 von 96 Publish a NuGet Package

School of Engineering © K. Rege, ZHAW 80 von 96 Acquire an API key

■ Goto: https://www.nuget.org/ ■ Sign in or create an account if you don't have one already.

■ Acquire your API key ■ Select your user name (on the upper right), then select API Keys. ■ Select Create, provide a name for your key, select Select Scopes > Push. Under API Key, enter * for pattern, then select Create. (See below for more about scopes.) ■ Once the key is created, select Copy to retrieve the access key you need e.g. in the CLI:

School of Engineering © K. Rege, ZHAW 81 von 96 Publish your Package via HTML Page

■ Uploading a Package via Web Upload ■ You can simply upload your .nupkg file to via ■ https://www.nuget.org/packages/manage/upload

■ Nuget will open your package, read the .nuspec file, and publish your package all in a single step.

School of Engineering © K. Rege, ZHAW 82 von 96 Publish your Package via CLI

■ nuget.exe has the ability of uploading your package automatically - this means you can write a script to automatically build and deploy your package simply and without interaction.

■ In order to upload your package via nuget.exe, we need to set the API key. You can create an API key from within your account on Nuget.Org.

■ Once you've set the API Key, you can push your package nuget.exe config setApiKey aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee nuget.exe push [your-package-filename].nupkg -Source https://www.nuget.org/api/v2/package

■ This can/should be automated with Powershell in the build process

School of Engineering © K. Rege, ZHAW 83 von 96 .NET on Linux & NUnit

School of Engineering © K. Rege, ZHAW 84 von 96 Run within W10

■ Simply get from the Store e.g. 18.04 LTS

■ However to use it, WSL must also be enabled ■ Enabling Windows Subsystem for Linux by use of PowerShell (as Administrator)

Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux https://www.windowscentral.com/install-windows-subsystem-linux-windows-10

School of Engineering © K. Rege, ZHAW 85 von 96 Install .NET SDK and NUnit on Ubuntu

■ install the necessary repository wget -q https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod. sudo -i packages-microsoft-prod.deb

■ A dependency that must be installed

sudo add--repository universe sudo apt-get install apt-transport-https

■ install DotNet Core 5 with these commands:

sudo apt-get update sudo apt-get install -y dotnet-sdk-5.0 https://www.techrepublic.com/article/how-to-install-dotnet-core-on-ubuntu-18-04/ https://docs.microsoft.com/en-us/dotnet/core/install/linux-ubuntu ■ install NUnit auf Ubuntu sudo apt-get install https://www.devmanuals.net/install/ubuntu/ubuntu-12-04-lts-precise-pangolin/install-nunit.html

School of Engineering © K. Rege, ZHAW 86 von 96 A Simple NUnit Test Command Line

■ Write Class, NUnit TestCase and Project File namespace Bank { namespace Bank { public class Account { using NUnit.Framework; private decimal balance; public void Deposit(decimal amount) { [TestFixture] balance += amount; public class AccountTest { } [Test] public decimal Balance { public void TestDeposit() { get { return balance; } Account source = new Account(); } source.Deposit(200m); } Assert.AreEqual(201m, source.Balance); otherwise an additional } otherwise an additional } mainmain is is generated generated } } ■ run it: NUnitTest.csprojNUnitTest.csproj dotnet test Starting test execution, please wait... Exe A total of 1 test files matched the specified pattern. net5.0 false Failed TestDeposit[19 ms] Error Message: Expected: 201m But was: 200m …. Failed! - Failed: 2, Passed: 0, Skipped: severalseveral users users probably probably /tmp/NuGetScratch/lock/xxx cannot https://nunit.org/nunitv2/docs/2.6.4/quickStart.html /tmp/NuGetScratch/lock/xxx cannot bebe deleted.-> deleted.-> remove remove manually manually School of Engineering © K. Rege, ZHAW 87 von 96 Fragen ?

School of Engineering © K. Rege, ZHAW 88 von 96 DOTNET CLI commands

■ The following commands can be passed to the dotnet program

add Add a package or reference to a .NET project. build Build a .NET project. build-server Interact with servers started by a build. clean Clean build outputs of a .NET project. help Show command line help. list List project references of a .NET project. migrate Migrate a project.json project to an MSBuild project. Run Microsoft Build Engine (MSBuild) commands. new Create a new .NET project or file. nuget Provides additional NuGet commands. pack Create a NuGet package. publish Publish a .NET project for deployment. remove Remove a package or reference from a .NET project. restore Restore dependencies specified in a .NET project. run Build and run a .NET project output. sln Modify Visual Studio solution files. store Store the specified assemblies in the runtime package store. test Run unit tests using the test runner specified in a .NET project. tool Install or manage tools that extend the .NET experience. vstest Run Microsoft Test Engine (VSTest) commands.

School of Engineering © K. Rege, ZHAW 89 von 96 … DOTNET CLI commands

■ Additional commands from bundled tools:

dev-certs Create and manage development certificates. ef Core command-line tools. sql-cache SQL Server cache command-line tools. user-secrets Manage development user secrets. watch Start a file watcher that runs a command when files change.

School of Engineering © K. Rege, ZHAW 90 von 96 NuGet Commands

School of Engineering © K. Rege, ZHAW 91 von 96 NuGet Secondary Commands

School of Engineering © K. Rege, ZHAW 92 von 96 .nuspec XML File Element

https://www.errlog.io/blogs/2017/12/creating-a-nuget-package

School of Engineering © K. Rege, ZHAW 93 von 96 Copy Files from Linux to/from Windows

■ start explorer.exe . in wsl

■ or via bash command e.g. ls /mnt/c

School of Engineering © K. Rege, ZHAW 94 von 96 An NUnit Test in Visual Studio

■ Create an NUnit Test Project

■ Or add the following Packages to the project

■ Start via Test Menu

School of Engineering © K. Rege, ZHAW 95 von 96 … further Installation VS 19

School of Engineering © K. Rege, ZHAW 96 von 96