Modern .NET gives you several ways to publish an app — single-file, trimmed, ReadyToRun, NativeAOT — and it is easy to assume one of them already hides your code. Mostly they do not. Only one of them removes the IL a decompiler reads, and it comes with constraints that rule it out for most apps. Here is what each option really does to your code, and where obfuscation still fits.
The thing that matters: is there still IL to read?
A .NET decompiler like ILSpy reconstructs readable C# from the IL and metadata inside your assemblies — that is the whole mechanism, covered in how decompilers read your code. So the only question that decides whether a publish option protects you is simple: after you publish, is your IL still in there? For every option below except one, the answer is yes — the IL is present and fully decompilable, just packaged differently.
| Publish option | What it is for | IL still present? | Decompilable? |
|---|---|---|---|
| Single-file | One-file distribution | Yes — bundled | Yes |
| Trimmed | Smaller output | Yes — minus unused | Yes |
| ReadyToRun | Faster startup | Yes — alongside native | Yes |
| NativeAOT | Native, no runtime/JIT | No | Not as .NET |
Single-file: a wrapper, not a vault
PublishSingleFile=true bundles your app and its dependencies into one
executable. It is a packaging convenience — the managed assemblies inside are ordinary IL,
embedded in the bundle and loaded at runtime. Readily available tooling unpacks the bundle
back into its component .dll files, and from there a decompiler reads them
exactly as it would any other assembly. A single-file publish makes your app tidier to
distribute; it does nothing to protect what is inside.
Obfuscation still applies, and the order is what you would expect: obfuscate the
assemblies first, then publish single-file. You protect the individual
.dll / .exe, and the bundle is built from the protected versions.
Trimming: a size feature that shares obfuscation's one pitfall
PublishTrimmed=true removes IL your app does not use, to shrink the output.
It is not a protection feature — whatever code survives the trim is still complete,
readable IL. What is worth knowing is that trimming and obfuscation fail in the
same narrow way: both rely on seeing how your code is used, and both can be
defeated by code that is reached only by reflection. A member looked up by
name at runtime can be trimmed away (because the trimmer did not see the call) or renamed
out from under the lookup (because the obfuscator did). If you already keep your
reflection surfaces safe for trimming — with DynamicDependency, trimmer roots,
or simply avoiding name-based lookups — you have done most of the work that keeps
obfuscation safe too. The same traps and fixes are in
obfuscation and reflection.
ReadyToRun: precompiled, but the IL stays
ReadyToRun (PublishReadyToRun=true) compiles your IL to native code ahead of
time so the app starts faster without waiting for the JIT. The catch, for protection
purposes, is that R2R does not replace the IL — it ships native code
alongside the original IL, which the runtime keeps as a fallback for scenarios the
precompiled code cannot serve. Your assemblies still carry full IL and metadata, so a
decompiler reads them normally. R2R is a startup-time optimisation; treat it as neutral for
protection and obfuscate as usual.
NativeAOT: the one that actually removes your IL — with strings attached
NativeAOT is the exception. It compiles your whole app ahead of time into a native binary with no IL, no metadata-rich managed assemblies, and no JIT. Point a .NET decompiler at a NativeAOT executable and there is nothing for it to read as .NET — the output is native machine code, the same wall you hit with a C++ program. That is a genuine, strong barrier against .NET-specific reverse engineering, and it is not something obfuscation provides.
But it is not a drop-in, and it is not free:
- It rules out whole categories of code. NativeAOT needs a closed world at compile time: no runtime code generation, heavily restricted reflection, no assembly loading, and only AOT-compatible libraries. Many real apps — anything leaning on reflection-based serializers, plug-ins, or frameworks that emit code — cannot be published this way without significant rework, and some cannot at all.
- It is not the same as obfuscation, and does not replace its layers. AOT removes the IL; it does not encrypt your strings, hide your call targets, or add a tamper check. Literals and embedded data can still be recovered from a native binary. What AOT changes is the kind of reverse engineering an attacker must do — from reading decompiled C# to analysing native code — which is a much higher bar, but not an impassable one. Native software gets reverse-engineered every day.
- IL-level obfuscation does not apply to the AOT output. There is no IL left to rename once AOT has run, so an IL obfuscator operates on the input, not the native result. In practice, if you can ship NativeAOT, you are choosing it instead of IL obfuscation for that binary, not alongside it.
Where obfuscation fits in a modern publish
For every publish mode except NativeAOT, your shipped code is still IL, so the decision is the ordinary one: if the binary lands on a machine you do not control, protect it. Slot obfuscation in before the publish step that packages or precompiles — obfuscate the assemblies, then let single-file, trimming or R2R do their job on the protected output. This mirrors the rule for signing, which also runs after obfuscation rewrites the assembly; see obfuscation and code signing: do them in the right order.
And keep the whole exercise anchored to the actual question — who can get a copy of this file? A single-file or trimmed publish that never leaves your servers needs no obfuscation at all, for the reasons in do you need to obfuscate server-side code? Once you have decided a shipped artifact is worth protecting, the layer decision guide matches each layer to the threat it answers, and what obfuscation actually protects against keeps the expectations honest.