Skip to content
  • Home
  • About
  • No Access
  • Privacy Policy
Bits of .NET
Bits of .NET
  • Asp.Net Core
  • C#
  • SQL
  • JavaScript
  • CSS
  • About
  • ErcanOPAK.com
  • No Access
  • Privacy Policy

Bits of .NET

Daily micro-tips for C#, SQL, performance, and scalable backend engineering.

  • Asp.Net Core
  • C#
  • SQL
  • JavaScript
  • CSS
  • About
  • ErcanOPAK.com
  • No Access
  • Privacy Policy
Asp.Net Core

.NET Core: Publish as Native AOT for Self-Contained Executables

- 05.06.26 - ErcanOPAK

📦 One EXE, No Runtime, Instant Start

.NET apps need runtime installed. Native AOT compiles to single native executable. Works on machines without .NET. 10ms startup.

🔧 Enable Native AOT

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net8.0</TargetFramework>
    <PublishAot>true</PublishAot>
  </PropertyGroup>
</Project>

# Publish command
dotnet publish -c Release -r win-x64 --self-contained
# Output: single .exe file (~10-30MB)

🎯 AOT Limitations

// ❌ Reflection (some may work, some not)
Type.GetType("SomeType")  // May return null

// ❌ Dynamic code generation
Assembly.Load(byte[])  // Not supported

// ❌ Newtonsoft.Json (uses reflection heavily)
// Use System.Text.Json with source generation instead

// ✅ Source-generated serialization
[JsonSourceGenerationOptions(WriteIndented = true)]
[JsonSerializable(typeof(MyClass))]
internal partial class MyJsonContext : JsonSerializerContext { }

var json = JsonSerializer.Serialize(obj, MyJsonContext.Default.MyClass);

✅ Perfect For

  • CLI tools (git-like, small, fast)
  • AWS Lambda/Azure Functions (cold start elimination)
  • Microservices in containers (small images)
  • Embedded/IoT devices (no runtime install)

“CLI tool required .NET runtime on customer machines. Native AOT compiled to single 15MB .exe. Customers copy and run. No install, no dependencies. Game changer.”

— Tool Developer

Related posts:

ASP.NET Core: Fix a Background Task That Gets Cancelled the Moment the HTTP Request That Started It ...

ASP.NET Core: Fix a Background Task That Gets Cancelled the Moment the HTTP Request That Started It ...

.NET Core: Scaling with Redis and IDistributedCache

.NET Core: Scaling with Redis and IDistributedCache

Async Streams in C# — Clean, Fast, Real-Time Data

Async Streams in C# — Clean, Fast, Real-Time Data

Views: 35

Post navigation

Git: Use Git Stash Show to See What’s in a Stash
SQL: Use WITH RECURSIVE to Query Hierarchical Data

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

November 2026
M T W T F S S
 1
2345678
9101112131415
16171819202122
23242526272829
30  
« Oct    

Most Viewed Posts

  • How to make theater mode the default for Youtube (1,055)
  • Get the User Name and Domain Name from an Email Address in SQL (980)
  • How to add default value for Entity Framework migrations for DateTime and Bool (977)
  • Get the First and Last Word from a String or Sentence in SQL (857)
  • How to select distinct rows in a datatable in C# (853)
  • How to enable, disable and check if Service Broker is enabled on a database in SQL Server (653)
  • Add Constraint to SQL Table to ensure email contains @ (608)
  • Average of all values in a column that are not zero in SQL (570)
  • How to use Map Mode for Vertical Scroll Mode in Visual Studio (546)
  • Find numbers with more than two decimal places in SQL (475)

Recent Posts

  • C#: Fix a ConditionalWeakTable Entry Vanishing Too Soon
  • Docker: Fix a Stale COPY Layer After Editing .dockerignore
  • Photoshop: Fix a Pattern Overlay Scaling Wrong on a High-DPI File
  • SQL Server: Fix a Computed Column Index Skipped by Implicit Cast
  • HTML5: Fix a required Input Inside a Hidden Tab Blocking Submit
  • SQL Server: Fix ROW_NUMBER Ties Reordering Between Identical Runs
  • C#: Fix an Enum HasFlag Returning True for the Zero Value
  • WordPress: Fix Featured Images Vanishing After a CDN Migration
  • Photoshop: Fix Content-Aware Fill Smearing a Repeating Pattern
  • Asp.Net Core: Fix Antiforgery Tokens Rejected Behind a Reverse Proxy

Most Viewed Posts

  • How to make theater mode the default for Youtube (1,055)
  • Get the User Name and Domain Name from an Email Address in SQL (980)
  • How to add default value for Entity Framework migrations for DateTime and Bool (977)
  • Get the First and Last Word from a String or Sentence in SQL (857)
  • How to select distinct rows in a datatable in C# (853)

Recent Posts

  • C#: Fix a ConditionalWeakTable Entry Vanishing Too Soon
  • Docker: Fix a Stale COPY Layer After Editing .dockerignore
  • Photoshop: Fix a Pattern Overlay Scaling Wrong on a High-DPI File
  • SQL Server: Fix a Computed Column Index Skipped by Implicit Cast
  • HTML5: Fix a required Input Inside a Hidden Tab Blocking Submit

Social

  • ErcanOPAK.com
  • GoodReads
  • LetterBoxD
  • Linkedin
  • The Blog
  • Twitter
© 2026 Bits of .NET | Built with Xblog Plus free WordPress theme by wpthemespace.com