A team adopts .NET Aspire, wires up an AppHost, and reaches the point of shipping. The first question is almost always the wrong one: "how do I obfuscate my Aspire app?" There is no single Aspire app to obfuscate. An Aspire solution is a set of ordinary .NET services plus a dev-time model that describes how they fit together. Knowing which of those assemblies actually reaches a customer — and which never leaves your build machine — decides the entire protection strategy, and it is simpler than it looks.
The AppHost is a blueprint, not a binary you ship
Open a fresh Aspire solution and you get three kinds of project: the AppHost, a shared ServiceDefaults library, and one or more services (an API, a web front end, workers). It is tempting to treat the AppHost as the application, because it is where you press F5. It is not. The AppHost is an orchestration model. Its whole job is to build a graph of resources and their relationships:
var builder = DistributedApplication.CreateBuilder(args);
var api = builder.AddProject<Projects.ApiService>("apiservice");
builder.AddProject<Projects.Web>("webfrontend")
.WithReference(api);
builder.Build().Run();
Those Projects.ApiService and Projects.Web types are not something you wrote. Aspire's source generator emits one metadata type per referenced project into the AppHost assembly, carrying the project path so the host can launch it. The AppHost uses them at development time to start processes, and at publish time to emit a deployment manifest (aspire-manifest.json) that a deployment tool consumes. In neither mode does the AppHost assembly travel to production as running code your customer can pull apart. It is a build artifact.
So the first rule writes itself: do not obfuscate the AppHost. There is no IP in a resource graph that an attacker could not reconstruct from watching the deployed topology, the generated Projects.* types are compiler plumbing, and the manifest step wants a clean, predictable assembly. Exclude it and spend the protection budget where code actually ships.
Services talk by name, not by type
The property that makes Aspire pleasant to obfuscate is how services find each other. When the web front end calls the API, it does not hold a reference to an API type. It makes an HTTP call to a logical name:
builder.Services.AddHttpClient<ApiClient>(c =>
c.BaseAddress = new("https+http://apiservice"));
apiservice is the name you gave the resource in the AppHost, nothing more. At runtime, service discovery resolves it from configuration that the orchestrator injects as environment variables when it starts the process — one key per endpoint:
Services__apiservice__https__0 = https://10.0.3.14:8443
Services__apiservice__http__0 = http://10.0.3.14:8080
Read that carefully, because it is the whole argument. The link between two services is a configuration string and an endpoint URL. It is not a reflected type name, not an assembly name, not a method. When Nebula renames ApiService.OrderController.PlaceOrder to a.b.c, the web front end still calls https+http://apiservice/orders and still resolves apiservice from the same injected key. The rename cannot reach across the process boundary, because the process boundary is an HTTP boundary and nothing managed crosses it.
This is a genuinely nicer position than an in-process monolith. In a monolith, two components that share a managed type must be renamed with one coordinated map or the shared type's identity drifts apart. Aspire's services never share a managed type at runtime — they share a wire contract — so you can obfuscate apiservice.dll and webfrontend.dll on independent seeds with no coordination at all.
The three things that still bite
Independence stops exactly at the data that crosses the wire, and at the shared project that both services compile against. Three surfaces need care.
Serialized DTOs. The HTTP contract is JSON, and System.Text.Json binds by property name. If apiservice returns an OrderResult and webfrontend deserializes it, both sides agree on "orderId", "total", and so on — by name. Rename the property on either side and the field silently vanishes from the payload:
// before — serializes { "orderId": 4012, "total": 59.90 }
public sealed class OrderResult
{
public int OrderId { get; set; }
public decimal Total { get; set; }
}
// after a blind rename — the JSON key changes with the property name
.property instance int32 a() { .get instance int32 OrderResult::get_a() }
// System.Text.Json now writes { "a": 4012, ... } and the caller sees null
The fix is the same keep-rule any serialized web type needs: exclude the DTO properties from renaming, or pin the names with [JsonPropertyName] so the wire key is decoupled from the member name. Nebula's keep-list handles this declaratively — match the DTO namespace and preserve public property names, while the method bodies and everything internal stay fully obfuscated.
Configuration binding. Services bind options from configuration — including the service-discovery and connection-string values Aspire injects. builder.Services.Configure<SmtpOptions>(config.GetSection("Smtp")) matches SmtpOptions.Host to the Smtp:Host key by property name. Renamed, the binding returns a default and the feature misconfigures at runtime with no exception. Options classes bound from configuration belong in the keep-list for the same reason DTOs do.
ServiceDefaults. This is the one assembly shared in managed form rather than over the wire. Each service's Program.cs calls into it:
builder.AddServiceDefaults(); // OpenTelemetry, health checks, service discovery
// ...
app.MapDefaultEndpoints(); // /health and /alive
AddServiceDefaults is a public method in ServiceDefaults.dll, called from every service assembly. If you obfuscate ServiceDefaults.dll alone and rename that public method, every caller breaks — the call site in apiservice.dll still looks for AddServiceDefaults. The answer is not to keep the method public-named forever; it is to obfuscate the solution as a unit, so the renamer rewrites the method and all its call sites together across assemblies. This is ordinary multi-project obfuscation: group ServiceDefaults with its consumers under one run, and the public plumbing can be renamed freely because the obfuscator sees both ends. Note the endpoint strings "/health" and "/alive" are literals, not symbols — they are untouched by renaming and keep working.
Where the heavy transforms go
With the boundaries kept, point the real protection at the code that carries value inside each service: licensing and entitlement checks, pricing and quota logic, key derivation, any proprietary algorithm. Apply control-flow flattening, string encryption, and — on the few methods that justify the runtime cost — code virtualization to those methods specifically, exactly as you would in a single-service build. The Aspire shape does not change what you protect; it changes only the packaging around it. A reasonable Nebula configuration obfuscates every service project, keeps the serialized and config-bound surface, excludes the AppHost, and runs on the build output before dotnet publish produces container images:
{
"input": "apiservice.dll",
"keep": [
"ApiService.Contracts.*",
"ApiService.Options.*"
],
"controlFlow": "aggressive",
"stringEncryption": true,
"virtualize": [ "ApiService.Licensing.*" ]
}
Takeaway
An Aspire solution is not one app with a special protection story; it is several ordinary services whose coupling happens to be string-based and out-of-process, orchestrated by an AppHost you never ship. That makes the strategy clean: skip the AppHost, obfuscate each service on its own seed, keep the JSON and configuration surfaces that cross the boundary, and obfuscate ServiceDefaults together with the services that call it. Then aim the heavy transforms at the enforcement and business logic inside each process — which is where they belonged all along. For the full keep-rule reference, see the Nebula configuration docs, and verify the result with Glass.NET.
Top comments (0)