Skip to main content

Utils Commands - .NET

dotnet new webapi

# Minimal version
dotnet new web

dotnet new list

dotnet new gitignore

# nuget.org // .NET Gallery
dotnet add package Microsoft.EntityFrameworkCore.InMemory --version 6.0.3

# Razor
dotnet new webapp

dotnet new page --name Pizza --namespace RazorPagesPizza.Pages --output Pages

# --- EF (Entity Framework) Core Migrations -----------------

# Install globally
dotnet tool install -g dotnet-ef

# Update 
dotnet tool update -g dotnet-ef

# Generate EF Core migrations
dotnet ef migrations add InitialCreate

# Execute EF Core migrations
dotnet ef database update

#----------- Udemy E-commerce course ------------
# create new solution file
dotnet new sln

# create webapi in API directory
dotnet new webapi -o API

# add API into the solution file
dotnet sln add API

# run the app
dotnet run

# update dotnet-ef (migration tool)
dotnet tool update --global dotnet-ef

# generate migrations in a specific folder
dotnet ef migrations add InitialCreate -o Data/Migrations

dotnet ef database update

dotnet ef database drop

dotnet watch run
dotnet watch
dotnet watch --no-hot-reload

# sync/download dependencies
dotnet restore

# Add migration
dotnet ef migrations add BasketEntityAdded

# Secrets manager
# https://learn.microsoft.com/en-us/aspnet/core/security/app-secrets?view=aspnetcore-7.0&tabs=windows
dotnet user-secrets init
dotnet user-secrets set "Movies:ServiceApiKey" "12345"
dotnet user-secrets list

#----------------------------------------------

dotnet tool list -g
dotnet tool update dotnet-ef -g

#---- Revert a migration---
dotnet ef migrations list
dotnet ef database update NameOfYourMigration #In the place of NameOfYourMigration enter the name of the migration you want to revert to.

#Then you can remove all the reverted migrations for good using
dotnet ef migrations remove

#--- Production --
dotnet publish -o out
dotnet out/Program.dll