Table of contents
  1. Docs
  2. Environment Variables
  3. Install
    1. Windows PowerShell
    2. PowerShell Core
    3. Bash
    4. Apt
  4. WinGet
    1. Chocolatey
  5. Update
    1. Upgrade CLI templates
      1. Checking for Updates
      2. Applying Updates
  6. Linux
    1. ARM64
      1. dotnet tool
    2. File Locations
    3. Environment Variables
      1. For Framework dependent apps , x64 , ARCH
  7. Run
  8. HttpRepl
  9. Create
  10. Run
  11. HttpRepl
    1. Set text editor for POST
    2. list and select controllers
    3. POST
    4. GET
  12. Entity Framework
    1. install
    2. create db tables
    3. apply create
    4. revisions
    5. update
    6. Build scafolding
  13. Resources
    1. dotnet 6 and ubuntu
      1. Ubuntu Packages
    2. - Build Web API Tutorial
    3. - ASP.net Core




Docs

Environment Variables

Install

Windows PowerShell

Invoke-WebRequest -Uri https://dot.net/v1/dotnet-install.ps1 -OutFile "$env:temp/dotnet-install.ps1"; powershell -executionpolicy bypass "$env:temp/dotnet-install.ps1"

PowerShell Core

Invoke-WebRequest -Uri https://dot.net/v1/dotnet-install.ps1 -OutFile "$env:temp/dotnet-install.ps1"; pwsh "$env:temp/dotnet-install.ps1"

Bash

wget https://dot.net/v1/dotnet-install.sh && chmod +x ./dotnet-install.sh && sudo ./dotnet-install.sh

Apt

sudo apt update
sudo apt install dotnet6

WinGet

winget install Microsoft.DotNet.SDK.6

Chocolatey

choco upgrade dotnet-sdk

Update

Upgrade CLI templates

Checking for Updates

Check if there are updates available for the template packs that are currently installed. Available since .NET Core 3.0 SDK.

dotnet new --update-check

Applying Updates

Check if there are updates available for the template packs that are currently installed and installs them. Available since .NET Core 3.0 SDK.

dotnet new --update-apply

Linux

ARM64

dotnet tool

dotnet tool install --arch arm64

File Locations

 /usr/local/share/dotnet
 /etc/dotnet
 ~/.dotnet
Anything below 3.1.415 and 5.0.403 is not supported on M1 hardware (because it installs into the wrong location). As per the issues referenced above, the recommended action is to: - Completely clear the entire /usr/local/share/dotnet - Install the latest versions only (which should install into the correct locations)

Environment Variables

For Framework dependent apps , x64 , ARCH

I DON’T KNOW IF THIS HELPS, ENV SHOULD BE SET AUTOMATICALLY WHEN INSTALLING,USE CAUTION
set in ~/.zshenv

export DOTNET_ROOT_ARM64=/usr/local/share/dotnet
export DOTNET_ROOT_X64=/usr/local/share/dotnet/x64

Run

dotnet run --urls=https://localhost:5101

HttpRepl

Create

dotnet new webapi -controllers -f net8.0.101

Run

dotnet run --urls=https://localhost:5101

HttpRepl

::install
 dotnet tool install -g Microsoft.dotnet-httprepl;

::set path to tools
export PATH="$PATH:/Users/bp/.dotnet/tools";

::test web api
httprepl http://localhost:5001

Set text editor for POST

pref set editor.command.default "/Applications/Visual Studio Code.app/Contents/Resources/app/bin/code"

set default args

        pref set editor.command.default.arguments "--disable-extensions --new-window"

list and select controllers

ls
cd [controller]

POST

post -h Content-Type=application/json

GET

get Order

return

[
  {
    "date": "2024-05-14",
    "summary": "order3"
  },
  {
    "date": "2024-05-15",
    "summary": "order5"
  },
  {
    "date": "2024-05-16",
    "summary": "order4"
  },
  {
    "date": "2024-05-17",
    "summary": "order4"
  },
  {
    "date": "2024-05-18",
    "summary": "order5"
  }
]

Entity Framework

install

dotnet add package Microsoft.EntityFrameworkCore.Sqlite;
dotnet add package Microsoft.EntityFrameworkCore.Design;
dotnet tool install --global dotnet-ef;

create db tables

in Program.cs add

using RestfulOrderAPI.Data;

///

builder.Services.AddSqlite<OrderContext>("Data Source=RestfulOrderAPI.db");

initial migrations

dotnet ef migrations add InitialCreate --context OrderContext

apply create

dotnet ef database update --context OrderContext

revisions

dotnet ef migrations add ModelRevisions --context OrderContext

update

dotnet ef database update --context OrderContext

Build scafolding

dotnet ef dbcontext scaffold "Data Source=./Promotions/Promotions.db" Microsoft.EntityFrameworkCore.Sqlite --context-dir ./Data --output-dir .\Models
The preceding command: - Scaffolds a DbContext and model classes using the provided connection string. - Specify the Microsoft.EntityFrameworkCore.Sqlite database provider should be used. - Specify directories for the resulting DbContext and model classes.

Resources

- Build Web API Tutorial

- ASP.net Core