1. Create a New Project


dotnet new webapi -n MyWebApi // Create a new Web API project
dotnet new mvc -n MyMvcApp // Create a new MVC project
dotnet new razor -n MyRazorApp // Create a new Razor Pages project
dotnet new console -n MyConsoleApp // Create a new Console application

2. Run the Application


dotnet run // Run the application
dotnet build // Build the project
dotnet publish -c Release // Publish the project for production

3. Add NuGet Packages


dotnet add package Microsoft.AspNetCore.Mvc // Add ASP.NET Core MVC package
dotnet add package Microsoft.EntityFrameworkCore // Add Entity Framework Core package

4. Remove NuGet Packages


dotnet remove package Microsoft.AspNetCore.Mvc // Remove ASP.NET Core MVC package
dotnet remove package Microsoft.EntityFrameworkCore // Remove Entity Framework Core package

5. Update NuGet Packages


dotnet update package Microsoft.AspNetCore.Mvc // Update ASP.NET Core MVC package
dotnet update package Microsoft.EntityFrameworkCore // Update Entity Framework Core package

6. List NuGet Packages


dotnet list package // List all NuGet packages

7. Create a New Class Library


dotnet new classlib -n MyClassLib // Create a new class library

8. Create a New Unit Test Project


dotnet new xunit -n MyUnitTestProject // Create a new unit test project

9. Run Unit Tests


dotnet test // Run unit tests

10. Create a New Web Application


dotnet new web -n MyWebApp // Create a new web application

11. Create a New Console Application


dotnet new console -n MyConsoleApp // Create a new console application

12. Create a New Razor Pages Application


dotnet new razor -n MyRazorApp // Create a new Razor Pages application

13. Create a New Web API Application


dotnet new webapi -n MyWebApi // Create a new Web API application

14. Create a New MVC Application


dotnet new mvc -n MyMvcApp // Create a new MVC application

15. Create a New Class Library for .NET Standard


dotnet new classlib -n MyStandardClassLib -f netstandard2.0 // Create a new class library for .NET Standard

16. Create a New Unit Test Project for .NET Core


dotnet new xunit -n MyCoreUnitTestProject -f netcoreapp3.1 // Create a new unit test project for .NET Core

17. Create a New Web Application for .NET Core


dotnet new web -n MyCoreWebApp -f netcoreapp3.1 // Create a new web application for .NET Core

18. Create a New Console Application for .NET Core


dotnet new console -n MyCoreConsoleApp -f netcoreapp3.1 // Create a new console application for .NET Core

19. Create a New Razor Pages Application for .NET Core


dotnet new razor -n MyCoreRazorApp -f netcoreapp3.1 // Create a new Razor Pages application for .NET Core

20. Create a New Web API Application for .NET Core


dotnet new webapi -n MyCoreWebApi -f netcoreapp3.1 // Create a new Web API application for .NET Core

21. Create a New MVC Application for .NET Core


dotnet new mvc -n MyCoreMvcApp -f netcoreapp3.1 // Create a new MVC application for .NET Core

22. Create a New Project with Specific Framework


dotnet new webapi -n MyWebApi -f net5.0 // Create a new Web API project targeting .NET 5.0

23. Restore Dependencies


dotnet restore // Restore dependencies for the project

24. Publish the Application


dotnet publish -c Release -o ./publish // Publish the application to the ./publish directory

25. Run a Specific Project


dotnet run --project MyProject.csproj // Run a specific project

26. Add a New File


dotnet new file -n MyFile.txt // Create a new file in the project

27. Remove a Project


dotnet sln remove MyProject.csproj // Remove a project from the solution

28. Add a Project to a Solution


dotnet sln add MyProject.csproj // Add a project to the solution

29. List Projects in a Solution


dotnet sln list // List all projects in the solution

30. Create a New Solution


dotnet new sln -n MySolution // Create a new solution

31. Add a Project Reference


dotnet add MyProject.csproj reference MyClassLib.csproj // Add a project reference

32. Remove a Project Reference


dotnet remove MyProject.csproj reference MyClassLib.csproj // Remove a project reference

33. Create a New Global Tool


dotnet new tool -n MyTool // Create a new global tool

34. Install a Global Tool


dotnet tool install -g MyTool // Install a global tool

35. Uninstall a Global Tool


dotnet tool uninstall -g MyTool // Uninstall a global tool

36. Update a Global Tool


dotnet tool update -g MyTool // Update a global tool

37. List Global Tools


dotnet tool list -g // List all installed global tools

38. Create a New Dockerfile


dotnet new dockerfile // Create a new Dockerfile for the project

39. Build a Docker Image


docker build -t myapp . // Build a Docker image for the application

40. Run a Docker Container


docker run -d -p 8080:80 myapp // Run a Docker container from the image

41. Create a New API Controller


dotnet new controller -n MyApiController // Create a new API controller

42. Create a New MVC Controller


dotnet new controller -n MyMvcController -m MyModel // Create a new MVC controller with a model

43. Create a New Razor Page


dotnet new page -n MyPage // Create a new Razor page

44. Create a New View


dotnet new view -n MyView // Create a new view

45. Create a New Migration


dotnet ef migrations add InitialCreate // Create a new migration

46. Update Database


dotnet ef database update // Update the database to the latest migration

47. Rollback Migration


dotnet ef database update PreviousMigration // Rollback to a previous migration

48. List Migrations


dotnet ef migrations list // List all migrations

49. Create a New API Version


dotnet new api-version -n V1 // Create a new API version

50. Add Swagger to the Project


dotnet add package Swashbuckle.AspNetCore // Add Swagger to the project

51. Enable Swagger in Startup


public void ConfigureServices(IServiceCollection services) {
services.AddSwaggerGen(c => {
c.SwaggerDoc("v1", new OpenApiInfo { Title = "My API", Version = "v1" });
});
}

52. Use Swagger in the Application


public void Configure(IApplicationBuilder app, IWebHostEnvironment env) {
app.UseSwagger();
app.UseSwaggerUI(c => {
c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
});
}

53. Create a New API Client


dotnet new console -n MyApiClient // Create a new API client application

54. Add HttpClient to the Project


services.AddHttpClient(); // Add HttpClient to the services

55. Use HttpClient in a Service


public class MyService {
private readonly HttpClient _httpClient;

public MyService(HttpClient httpClient) {
_httpClient = httpClient;
}
}

56. Create a New gRPC Service


dotnet new grpc -n MyGrpcService // Create a new gRPC service

57. Add gRPC Client to the Project


dotnet add package Grpc.Net.Client // Add gRPC client package

58. Create a New Blazor App


dotnet new blazorserver -n MyBlazorApp // Create a new Blazor Server app
dotnet new blazorwasm -n MyBlazorWasmApp // Create a new Blazor WebAssembly app

59. Add SignalR to the Project


dotnet add package Microsoft.AspNetCore.SignalR // Add SignalR package

60. Create a New SignalR Hub


public class MyHub : Hub {
public async Task SendMessage(string user, string message) {
await Clients.All.SendAsync("ReceiveMessage", user, message);
}
}

61. Configure SignalR in Startup


public void ConfigureServices(IServiceCollection services) {
services.AddSignalR();
}

62. Use SignalR in the Application


public void Configure(IApplicationBuilder app, IWebHostEnvironment env) {
app.UseEndpoints(endpoints => {
endpoints.MapHub<MyHub>("/myhub");
});
}

63. Create a New Worker Service


dotnet new worker -n MyWorkerService // Create a new Worker Service

64. Add Background Service to the Project


public class MyBackgroundService : BackgroundService {
protected override async Task ExecuteAsync(CancellationToken stoppingToken) {
while (!stoppingToken.IsCancellationRequested) {
// Background task logic
await Task.Delay(1000, stoppingToken);
}
}
}

65. Configure Background Service in Startup


public void ConfigureServices(IServiceCollection services) {
services.AddHostedService<MyBackgroundService>();
}

66. Create a New API Key


dotnet user-secrets set "ApiKey" "YourApiKey" // Set an API key in user secrets

67. Access User Secrets in the Application


public void ConfigureServices(IServiceCollection services) {
var apiKey = Configuration["ApiKey"]; // Access the API key
}

68. Create a New Configuration File


dotnet new json -n appsettings.json // Create a new JSON configuration file

69. Load Configuration in Startup


public void ConfigureServices(IServiceCollection services) {
services.Configure<MySettings>(Configuration.GetSection("MySettings"));
}

70. Create a New Settings Class


public class MySettings {
public string Setting1 { get; set; }
public int Setting2 { get; set; }
}

71. Use Configuration in a Service


public class MyService {
private readonly MySettings _settings;

public MyService(IOptions<MySettings> settings) {
_settings = settings.Value;
}
}

72. Create a New Middleware


public class MyMiddleware {
private readonly RequestDelegate _next;

public MyMiddleware(RequestDelegate next) {
_next = next;
}

public async Task InvokeAsync(HttpContext context) {
// Middleware logic
await _next(context);
}
}

73. Use Middleware in Startup


public void Configure(IApplicationBuilder app, IWebHostEnvironment env) {
app.UseMiddleware<MyMiddleware>();
}

74. Create a New Custom Exception


public class MyCustomException : Exception {
public MyCustomException(string message) : base(message) {}
}

75. Handle Exceptions Globally


public void Configure(IApplicationBuilder app, IWebHostEnvironment env) {
app.UseExceptionHandler("/Home/Error");
}

76. Create a New Custom Filter


public class MyCustomFilter : IActionFilter {
public void OnActionExecuting(ActionExecutingContext context) {
// Logic before action executes
}

public void OnActionExecuted(ActionExecutedContext context) {
// Logic after action executes
}
}

77. Register Custom Filter Globally


public void ConfigureServices(IServiceCollection services) {
services.AddControllers(options => {
options.Filters.Add(new MyCustomFilter());
});
}

78. Create a New Custom Tag Helper


[HtmlTargetElement("my-tag")]
public class MyTagHelper : TagHelper {
public string Message { get; set; }

public override void Process(TagHelperContext context, TagHelperOutput output) {
output.Content.SetContent(Message);
}
}

79. Use Custom Tag Helper in a View


<my-tag message="Hello, World!"></my-tag>

80. Create a New Custom View Component


public class MyViewComponent : ViewComponent {
public IViewComponentResult Invoke() {
return View();
}
}

81. Use View Component in a View


@await Component.InvokeAsync("MyViewComponent")

82. Create a New Custom Action Result


public class MyCustomResult : IActionResult {
public async Task ExecuteResultAsync(ActionContext context) {
// Custom result logic
}
}

83. Use Custom Action Result in a Controller


public IActionResult MyAction() {
return new MyCustomResult();
}

84. Create a New Custom Model Binder


public class MyModelBinder : IModelBinder {
public Task BindModelAsync(ModelBindingContext bindingContext) {
// Custom binding logic
return Task.CompletedTask;
}
}

85. Register Custom Model Binder


services.AddControllers(options => {
options.ModelBinderProviders.Insert(0, new MyModelBinderProvider());
});

86. Create a New Custom Formatter


public class MyCustomFormatter : IInputFormatter {
public async Task<InputFormatterResult> ReadRequestBodyAsync(InputFormatterContext context, Encoding encoding) {
// Custom formatter logic
return await InputFormatterResult.SuccessAsync();
}
}

87. Register Custom Formatter


services.AddControllers(options => {
options.InputFormatters.Insert(0, new MyCustomFormatter());
});

88. Create a New Custom Service


public class MyCustomService {
public void DoSomething() {
// Service logic
}
}

89. Register Custom Service


services.AddScoped<MyCustomService>();

90. Inject Custom Service into a Controller


public class MyController : Controller {
private readonly MyCustomService _service;

public MyController(MyCustomService service) {
_service = service;
}
}

91. Create a New Custom Configuration Provider


public class MyCustomConfigurationProvider : ConfigurationProvider {
public override void Load() {
// Custom loading logic
}
}

92. Register Custom Configuration Provider


public void ConfigureServices(IServiceCollection services) {
var builder = new ConfigurationBuilder();
builder.Add(new MyCustomConfigurationProvider());
var configuration = builder.Build();
services.AddSingleton<IConfiguration>(configuration);
}

93. Create a New Custom Middleware for Logging


public class LoggingMiddleware {
private readonly RequestDelegate _next;

public LoggingMiddleware(RequestDelegate next) {
_next = next;
}

public async Task InvokeAsync(HttpContext context) {
// Log request details
await _next(context);
}
}

94. Use Logging Middleware in Startup


public void Configure(IApplicationBuilder app, IWebHostEnvironment env) {
app.UseMiddleware<LoggingMiddleware>();
}

95. Create a New Custom Exception Filter


public class MyCustomExceptionFilter : IExceptionFilter {
public void OnException(ExceptionContext context) {
// Handle exception
}
}

96. Register Custom Exception Filter Globally


public void ConfigureServices(IServiceCollection services) {
services.AddControllers(options => {
options.Filters.Add(new MyCustomExceptionFilter());
});
}

97. Create a New Custom Action Filter for Caching


public class CachingActionFilter : IActionFilter {
public void OnActionExecuting(ActionExecutingContext context) {
// Caching logic
}

public void OnActionExecuted(ActionExecutedContext context) {
// Logic after action executes
}
}

98. Register Caching Action Filter Globally


public void ConfigureServices(IServiceCollection services) {
services.AddControllers(options => {
options.Filters.Add(new CachingActionFilter());
});
}

99. Create a New Custom Tag Helper for Formatting


[HtmlTargetElement("format")]
public class FormatTagHelper : TagHelper {
public string Value { get; set; }

public override void Process(TagHelperContext context, TagHelperOutput output) {
output.Content.SetContent($"Formatted: {Value}");
}
}

100. Use Custom Tag Helper for Formatting in a View


<format value="Hello, World!"></format>