How to Create a Self Contained Dotnet Application or a Framework Independent App Using .NET SDK CLI

by xanthium-enterprises in Circuits > Software

405 Views, 1 Favorites, 0 Comments

How to Create a Self Contained Dotnet Application or a Framework Independent App Using .NET SDK CLI

How to Create a Self Contained dotnet App or a framework Dependent dotnet App using .NET SDK CLI

In this instructable,

We will learn How to build a self-contained dotnet (.NET) application from your source code using the .NET SDK CLI command line tools.


Another term often used interchangeably with "self-contained .NET application" is "deployable .NET application" or a " framework independent" application. Both terms refer to an application that includes all necessary components, including the .NET runtime and dependencies


If you are new to the .NET SDK CLI ,Please do check our tutorial on How to use .NET SDK to develop self contained applications on Windows and Linux.

We also have a video on building and publishing software using .NET SDK CLI tools for Absolute beginners on our channel

Supplies

image_19.png
Microsoft_.NET_logo.svg.png

For the software Development,

You have to download

1) .NET SDK CLI tools from Microsoft Website

2) Text Editor like Sublime text

What Is a .NET Self Contained Application

framework-independent-dotnet-application.jpg

A self-contained .NET application or a framework independent dotnet application bundles all necessary components, including the .NET runtime and dependencies, with the application itself, enabling it to run independently on target systems without relying on a pre-installed .NET framework.

This approach simplifies deployment, ensuring users can execute the application without additional setup. It guarantees consistent execution environments across different systems and enhances compatibility, as the application can run on systems with varying .NET framework versions or without .NET installed.

Self-contained applications are isolated from the system's global .NET installation. This means that any updates or changes to the system's .NET framework won't affect the application's behavior.

One Issue with packaging the .NET runtime and dependencies with the application increases the overall size of the application package, which can result in longer download times and increased disk space usage.

Difference Between Self -contained .NET App and Framework Dependent App

framework-independent-vs-framework-dependent.png

The difference between a self-contained .NET application and a framework-dependent .NET application lies in how they handle dependencies, particularly the .NET runtime.

A self-contained application includes all necessary components, such as the .NET runtime and dependencies, bundled together with the application itself. This enables it to run independently on target systems without relying on a pre-installed .NET framework, simplifying deployment and ensuring consistent execution environments.

A framework-dependent application relies on the presence of a compatible .NET framework already installed on the target system for execution. It does not include the .NET runtime with the application package, requiring users to install the framework separately. This approach may introduce dependencies on specific framework versions and compatibility concerns across different systems.

The decision to use either a self-contained .NET application or a framework-dependent .NET application depends on factors such as deployment requirements, target environments, and trade-offs acceptable to the application's stakeholders.

Self-contained applications simplify deployment by bundling all dependencies with the application itself, ensuring consistent execution environments and easing deployment, particularly in scenarios where the .NET framework may not be readily available. However, they may incur larger file sizes and longer deployment times. Framework-dependent applications rely on the presence of a compatible .NET framework already installed on the target system, potentially reducing file sizes and deployment times but introducing dependencies and compatibility concerns. 



Creating a Self -contained .NET App Using .NET SDK CLI

Creating a self-contained .NET application using the .NET SDK CLI involves a the following steps,


First navigate toyour Project directory using terminal commands

Use the dotnet publish command to publish your dotnet application, specifying the desired runtime identifier (RID) for the target platform. 

For example

dotnet publish -c Release -r <runtime_identifier>

Replace <runtime_identifier> with the appropriate runtime identifier for your target platform.

like win-x86 or win-x64


A detailed look on dotnet runtime identifier (rid) and how to use it create app for multiple platforms check our tutorial.

If you have multiple libraries and references creating a self containing app will become complex so do refer this tutorial