Skip to content

jeftegoes/DotnetOverviewAndCommands

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Dotnet overview and commands

Contents

1. What is C#

  • C# is a programming language.
  • Object Oriented.
  • Strongly typed.
  • Simple to use and general-purpose.
  • Some the things we can write in C#:
    • Backend Development (API, EF Core, Linq, Async, OOP)
    • Front End (ASP.Net, MVC, Razor, Blazor)
    • Mobile (Maui, Xamarin)
    • Game (Unity)
    • Desktop (Maui, WinForms, WPF)

2. What is .NET

  • A C# compiler.
  • A runtime to execute C# (Core CLR).
  • Libraries to provide out-of-the-box functionalities (BCL Functions).
  • A garbage collector to manage memory.
  • .NET (dotnet) is a framework for building applications on Windows, Linux and MAC OS.
    • .NET is not limited to C# examples are F# or VB.NET.

3. What is the difference between .NET Framework, .NET Core and .NET?

Dotnet timeline

4. How C# is compiled

5. Typical dotnet application

  • Typical dotnet application diagram
    • Tied to Windows and IIS.
    • First release: 2002 (no cloud, no Microservices).

6. Why Microsoft created .NET?

  • New requirements:
    • Cross-platform.
    • Open-Source.
    • "Similar" to classic .NET.
    • Good for cloud, good for microservices -> lightweight and fast.
  • PERFORMANCE!!!!
  • .NET Core diagram

6.1. Why does it matter?

  • Almost zero framework overhead = almost zero overhead for your application.
  • It's a C# library built on top of .NET: you have the same platform available for your libraries and applications.
  • Many C# features and new .NET APIs were "invented" during the development of .NET and ASP.NET to achieve this performance.

7. .NET Standard

  • Contract that defines an API surface.
  • Versions: 1.0 - 2.0.
  • A list of Types and methods that are available in different versions.
  • ".NET" flavors implement the standard.
  • .NET Standard version are backward compatible.

7.1. .NET Standard Why?

  • Code sharing!
  • Target the standard - run everywhere.
  • Full framework, .NET Core, Mono (Xamarin): all support .NET Standard 2.0.
  • As a library author: you should target .NET Standard (and not e.g. .NET Core).

7.2. Portable Class Library (PCL) and Shared Projects?

  • PCL and Shared Projects: Previous attempt to share code across .NET Platforms (e.g. Full Framework and Xamarin).
  • Recommendation: use .NET Standard.

7.3. .NET Standard 2.0

  • .NET Standard 2.0 versions
  • Doubled the number of APIs.
  • Supports mscorlib based .NET Framework libs.

8. Deployments options

8.1. Self contained

  • Contains the CLR.
  • No preinstalled framework needed.
  • Bigger deployment package which targets a specific OS (The executable is not cross-platform).
  • dotnet publish --runtime win-x86 --self-contained true

8.2. Framework Dependent

  • Only contains the application’s code.
  • Requires preinstalled .NET Core on the target machine.
  • Cross platform deployment package.
  • Small package size.
  • Default.
  • dotnet publish --runtime win-x86 --self-contained false

8.3. Package Size

Package size difference

9. Performance

9.1. Measuring memory

10. Commands

10.1. General commands

  • Create a Web API into the project
    • dotnet new webapi -o <output_path>
  • Add reference to another ClassLib
    • dotnet add <target_project> reference <project> # Ex: dotnet add Calculations.Test reference Calculations
  • Step By Step - Create class library into the project
    1. dotnet new classlib -o Infrastructure
    2. dotnet sln add "name of classlib"
    3. dotnet add reference ../classlib/
  • Step By Step - Run project
    1. First enter in the path it contains startup.cs file
    2. Second run command: dotnet run
    3. Optional: dotnet watch run
  • Restore project, download all dependencies of project
    • dotnet restore
  • All informations about dotnet in the machine
    • dotnet --info
  • Build project and generate release
    • dotnet publish -c Release
  • Verif if machines has https certificate valid
    • dotnet dev-certs https
  • Trust localhost certificate
    • dotnet dev-certs https -t
  • List of tools installer with dotnet
    • dotnet tool list -g # -g appear globar
  • Generate NuGet package
    • dotnet pack
    • OR
    • Adding this tag to automatically generate package on build:
      • true

10.2. Solution commands

  • Create a solution
    • dotnet new sln
  • Add project into a solution
    • dotnet sln add <dotnet_project> # Remember, he must exists .csproj file.

10.3. Aspnet codegenerator commands

  • dotnet aspnet-codegenerator --project "D:\CSharp\DotnetDapperOverview\ExampleDapper" controller --force --controllerName CompanyController --model ExampleDapper.Models.Company --dataContext ExampleDapper.Data.ApplicationDbContext --relativeFolderPath Controllers --controllerNamespace ExampleDapper.Controllers

11. Tools

  • dotnet tool install --global dotnet-aspnet-codegenerator --version X.X.X

Releases

No releases published

Packages

No packages published