Types of Deployment in .NET Core

๐Ÿ’ก Concept Name

Deployment Types in .NET Core

๐Ÿ“˜ Quick Intro

.NET Core supports multiple deployment models that determine how your application and its dependencies are delivered to the target system.

๐Ÿง  Analogy / Short Story

Think of Framework-Dependent Deployment as sending someone a shortcut to a file assuming they already have the app installed, while Self-Contained Deployment is like sending the whole application along with its own portable runtime.

๐Ÿ”ง Technical Explanation

  • ๐Ÿ“ฆ Framework-Dependent Deployment (FDD): App runs using a .NET runtime already installed on the host machine.
  • ๐Ÿš€ Self-Contained Deployment (SCD): Bundles your app + .NET runtime. No dependency on host machine.
  • ๐ŸŽฏ Single-file Executable: Optional publishing mode where the app and runtime are merged into one executable file.
  • ๐Ÿ›ก๏ธ Trimmed Deployment: Removes unused libraries to reduce final output size (used with SCD or single file).

๐ŸŽฏ Purpose & Use Case

  • โœ… FDD: Ideal for environments where .NET is pre-installed (e.g., internal servers).
  • โœ… SCD: Useful when you can't control target environments (cross-platform tools, Docker, external customers).
  • โœ… Single File: Simplifies distribution.
  • โœ… Trimming: Useful for microservices or embedded systems with size limits.

๐Ÿ’ป Real Code Example

Framework-Dependent Deployment:

dotnet publish -c Release -r win-x64 --self-contained false

Self-Contained Deployment:

dotnet publish -c Release -r linux-x64 --self-contained true

Single-File + Trimming:

dotnet publish -c Release -r win-x64 /p:PublishSingleFile=true /p:PublishTrimmed=true

โ“ Interview Q&A

Q1: What is Framework-Dependent Deployment?
A: A model where the app relies on .NET runtime already installed on the system.

Q2: What is Self-Contained Deployment?
A: It includes the app and the .NET runtime for maximum portability.

Q3: Can you create a single .exe file with .NET Core?
A: Yes, using PublishSingleFile option.

Q4: What is trimming?
A: Removing unused code from assemblies to reduce the app size.

Q5: Which deployment is best for unknown environments?
A: Self-contained deployment.

๐Ÿ“ MCQs

Q1. Which deployment relies on pre-installed .NET runtime?

  • Self-Contained Deployment
  • Framework-Dependent Deployment
  • Single File Deployment
  • Docker-based Deployment

Q2. Which deployment includes .NET runtime?

  • FDD
  • SCD
  • ILMerge
  • CLI Deployment

Q3. What does PublishSingleFile do?

  • Minifies code
  • Runs unit tests
  • Creates a single executable
  • Compresses app

Q4. What is the purpose of trimming?

  • Speed up build
  • Reduce app size
  • Enhance security
  • Enable logging

Q5. Which tool is used to deploy .NET apps?

  • dotnet run
  • dotnet compile
  • dotnet deploy
  • dotnet publish

๐Ÿ’ก Bonus Insight

For Docker-based deployments, Self-contained deployments are often used to ensure the container doesn't depend on the host OS's runtime environment. Alpine Linux images benefit significantly from trimming and single-file bundling.

๐Ÿ“„ PDF Download

Need a handy summary for your notes? Download this topic as a PDF!

๐Ÿ’ฌ Feedback
๐Ÿš€ Start Learning
Share:

Tags: