Skip to content

ADR-0010: Conditional projects in the .slnx template

  • Status: accepted
  • Date: 2026-07-15

The template must conditionally exclude projects (e.g. the Blazor UI when IncludeUI=false). The dotnet new engine excludes source files/folders via sources.modifiers, but the solution file still lists the excluded projects unless it is itself conditionally processed. Prior art warned that conditional processing inside the new XML .slnx format was unproven (dotnet/templating #8784), suggesting a classic .sln with #if blocks as a fallback.

Ship a .slnx and use XML-comment conditionals inside it:

<!--#if (IncludeUI) -->
<Folder Name="/src/Presentation/UI/">
<Project Path="src/Presentation/UI/Trellis.UI.Web/Trellis.UI.Web.csproj" />
</Folder>
<!--#endif -->

Verified empirically on the .NET 10 SDK template engine: IncludeUI=false strips the block (no UI projects, no leftover markers); IncludeUI=true keeps it clean. The content between the comment markers is active XML, so the .slnx remains a valid, buildable solution in the template repo itself.

Inline C# conditionals (AppHost web wiring) use an #if block on IncludeUI. Because the raw template source has no such preprocessor symbol, the AppHost project defines IncludeUI (via a DefineConstants property guarded by the same XML-comment conditional) so the repo compiles the "on" branch during development; the engine resolves the real condition at instantiation.

  • No .sln fallback needed — one modern .slnx, and the repo stays a runnable solution.
  • The exclusion pattern is uniform: sources.modifiers removes the folder, the .slnx conditional removes the references, and #if removes inline wiring.
  • Re-verify on major SDK bumps (the behavior is empirical, not documented); the template repository's instantiate-and-build CI matrix guards it.

The documentation of Trellis.Templates 0.2.0 · release notes