Aller au contenu

ASP.NET Core 10 CLI

De Banane Atomic

Nuget packages management

Run the commands from the solution or project folder.

# list outdated packages
dotnet list package --outdated

# update all outdated packages to to latest stable
dotnet package update

# list the installed packages
dotnet list package

# add a package
dotnet add package <package_name>
dotnet add package <package_name> --version 2.0.0

# remove a package
dotnet remove package <package_name>

Build

# restore and build with the release configuration
dotnet build --configuration Release

Run

# restore, build and run
dotnet run

# force url and port (default: http://127.0.0.1:5000)
ASPNETCORE_URLS="http://127.0.0.1:5123" dotnet run         # linux
dotnet run --ASPNETCORE_ENVIRONMENT Development            # powershell
$env:ASPNETCORE_URLS="http://127.0.0.1:5123" ; dotnet run  # powershell

Publish

dotnet10 publish --configuration Release --output publish

CI/CD pipeline

.gitea/workflows/deploy.yaml
name: Deploy
on:
  workflow_dispatch:

env:
  APP_NAME: Todo
  DEPLOY_PATH: /var/www/todo
  NGINX_SITE: /etc/nginx/sites-available/todo

jobs:
  deploy:
    runs-on: ubuntu-22.04
    steps:
    - name: Checkout
      uses: actions/checkout@v6

    - name: Restore
      run: dotnet restore

    - name: Build
      run: dotnet build --configuration Release --no-restore

    - name: Test  
      run: dotnet test --configuration Release --no-build || true

    - name: Publish
      run: dotnet publish --configuration Release --output publish --no-build

New solution / project

# list available templates (webapi, blazor)
dotnet new
# create a new Web API project
dotnet new webapi -o [project-name] --no-https

# create a solution file and folder
dotnet new sln --name MySolution
# add a project to the solution
dotnet sln add ./MyProject/MyProject.csproj

# add a reference to another project
dotnet add reference ../otherproject/otherproject.csproj

Miscellaneous

# get the versions of the installed .NET SDK, Host and runtimes
dotnet --info

# run all the unit tests
dotnet test