2081 5

CSC378 ยท 2081 ยท 5 marks

Describe the procedure of deploying .NET core application.

Describe the procedure of deploying .NET core application. [5]

NET Centric ComputingChapter 9: Hosting and Deploying ASP.NET Core ApplicationApp Servers and Hosting models

Quick answer

.NET Core is a cross-platform framework, and its Command-Line Interface (CLI) provides tools to build, run, test, and publish .NET Core applications. The .NET Core CLI is installed with the .NET Core SDK and does not need to be installed separately.

Deploying a .NET Core Application

Introduction


Step-by-Step Deployment Procedure

Step 1: Verify .NET Core CLI Installation

Before deploying, confirm that the CLI is properly installed by opening the command prompt and typing:

dotnet

If it displays usage information, the CLI is installed correctly.


Step 2: Create the Application

Create a new project directory and initialize the application using CLI commands:

mkdir myapp
cd myapp
dotnet new console

This creates the necessary project files:

  • Program.cs (main source file)
  • myapp.csproj (project configuration file)

Step 3: Restore Packages

Restore all required NuGet packages and dependencies:

dotnet restore

This ensures all dependencies defined in the .csproj file are downloaded and available.


Step 4: Build the Application

Compile the application to check for errors and generate the build output:

dotnet build

Note: When using .NET Core SDK, the application is built automatically when needed, so there is no need to worry about executing outdated code.


Step 5: Run the Application (Testing)

Test the application locally before deployment:

dotnet run

This compiles (if needed) and executes the application directly.


Step 6: Publish the Application

Publish the application to prepare it for deployment on a target server:

dotnet publish -c Release -o ./publish
  • -c Release specifies the Release configuration (optimized build)
  • -o ./publish specifies the output directory where published files are placed

This generates all necessary files (DLLs, configuration files, runtime files) in the output folder.


Step 7: Deploy to the Server

Copy the published output to the target server. For a web application, the deployment typically involves:

  • Placing the published files on the server
  • Configuring a reverse proxy (such as IIS, Nginx, or Apache)
  • The reverse proxy receives requests from the browser and passes them to the ASP.NET Core application, which runs a self-hosted web server (Kestrel)
Browser --> Reverse Proxy (IIS/Nginx) --> ASP.NET Core App (Kestrel)

Summary Table

StepCommandPurpose
Verify CLIdotnetCheck installation
Create Appdotnet new consoleInitialize project
Restoredotnet restoreDownload dependencies
Builddotnet buildCompile source code
Rundotnet runTest locally
Publishdotnet publishPrepare for deployment

Conclusion

The .NET Core CLI provides a simple and consistent cross-platform procedure for deploying applications. Higher-level IDEs like Visual Studio internally use the same CLI commands to restore, build, and publish .NET Core applications.

Short on time? The 1, 5 and 10 mark versions of this answer, flashcards and practice sets come with a program pass.