Analysis complete. Here is the assessment.
Analysis: sys create generates an .slnx solution file
Context discovered
sys create (internal/system/create.go) works in two distinct phases:
- Template render — calls
template.Create with the system-host template and exactly one value: name. The template contract is explicit in code: "the template's contract: only name, never prompt". The CLI then reads back template-derived values (projectName, systemClass) from the scaffold record to avoid derivation drift.
- Post-render codegen — the CLI itself writes
Topics.cs, Connectors.cs, <ProjectName>Development.cs, the system class file, and textually inserts a <ProjectReference> into the rendered csproj (csproj.go). These are not template-library content; they are Go text/template constants in internal/system/codegen.go.
So the precedent is already mixed: the shell comes from the library, the assembled declaration is generated CLI-side from the scanned model.
Feasibility
Fully feasible, and there are two viable placements that match your stated preference:
Option A — post-render generation in the CLI (lowest complexity, follows existing precedent)
The slnx content would live exactly where Topics.cs etc. live: a template constant in codegen.go, rendered from the model after the host render. This is the established pattern for everything sys create assembles from scaffold records. However — it contradicts your request that the CLI not contain the slnx template.
Option B — send the project list into the template render (your stated preference)
Pass a projects array in SetValues to template.Create and let the library's system-host skeleton carry a {{ .name }}.slnx.tmpl that ranges over it.
The mechanics:
system.Create would build the project list before calling template.Create. The data is available: each component scaffold entry has its directory path (Component.Path) and values; project file names may need a convention (e.g. template-derived PascalCase names recorded in scaffold values, similar to how the host reads back projectName). The shared library (model.Shared.Path / model.Shared.Name) and the host csproj ({{ .projectName }}.SystemHost.csproj, name templated by the library) also go in.
SetValues: map[string]any{"name": kebab, "projects": [...]} — map[string]any already supports slices, and the render engine is Go text/template with sprig, so {{ range .projects }} works with no CLI engine changes.
- One contract change: the system-host manifest declares
required: [name] and validates against JSON Schema. Adding a projects parameter (array of objects: path + csproj name, or a pre-formatted string list) requires a template-library release that adds the parameter, the skeleton file, and the schema entry. Old template releases would fail with missingkey=error if the skeleton referenced .projects without it — but since the skeleton only exists in the new release, old releases simply never generate an slnx. The CLI must then decide: warn (as it does for missing Development.cs placeholders — see writeDevelopmentFile's "template rendered no placeholder" fallback) or fail.
Key wrinkles to resolve:
- Where does the slnx live? A solution spanning host + components + contracts belongs at the workspace root (
opts.StartDir), not inside the host output dir. The current render targets only opts.OutputDir. Options: render it as part of the host skeleton into the host dir (wrong granularity, relative paths escape the dir), or — cleaner — have the CLI do a second, targeted render: after template.Create, render just the slnx skeleton file from the already-downloaded template with the full values map into StartDir. This keeps the template in the library (your requirement) while the CLI controls placement. This is a small extension: template.Create would need to expose the extracted template root or a RenderFile helper, since today the tarball is cleaned up inside template.Create.
- Project discovery fidelity.
Assemble keeps only Path per component — the csproj filename inside each scaffold dir is not in the model. The CLI must either glob *.csproj in each scaffold dir (fragile if multiple) or require the scaffold record to carry the project name (check whether extractor/loader templates record it; the host reads back projectName from its own record, so the convention exists but must be verified for component templates).
- slnx format. The XML slnx format (
<Solution><Project Path="..." /></Solution>) is trivially templateable — simpler than .sln (no GUIDs required; VS 17.10+/dotnet sln support it). Paths must be slash-separated and relative to the slnx location.
Complexity added
- Low-to-moderate. No new CLI engine machinery:
SetValues and range rendering already exist. The only genuinely new capability is rendering a file outside the host output dir (second-render step or exposed render helper) — roughly one function plus tests.
- Version-coupling cost (the real complexity): the feature needs a coordinated template-library release. The CLI must handle old releases gracefully (warn-and-skip, mirroring the
Development.cs legacy path in codegen.go), which adds a fallback branch and test fixtures. This is a known, already-paid pattern in this codebase.
- Testing: fixture tarball additions in
create_test.go (an slnx skeleton entry), plus cases for old-release-without-slnx and project-name discovery failures.
Where the change belongs
Split, as you suggested:
| Concern | Location |
|---|
slnx file content/shape (XML skeleton, {{ range .projects }}) | Template library — new {{ .name }}.slnx.tmpl (or fixed slnx.tmpl with templated name) in the system-host template, plus a projects parameter in its schema |
| Project list assembly (scan model → path/csproj-name pairs, relative-path computation from workspace root) | CLI — internal/system, alongside Assemble; this is workspace knowledge the library cannot have |
Render orchestration (pass projects in SetValues; render/place the slnx at workspace root; warn on old template releases) | CLI — system.Create |
This matches the existing architecture precisely: the library owns file shape, the CLI owns assembly (same split as csproj ProjectReference insertion, where the path computation is CLI-side). One caveat: because placement is the workspace root rather than the host dir, a pure "values in, skeleton out" single render won't cover it — the CLI needs a small post-render step. If you want zero post-render steps, the alternative is nesting the slnx inside the host dir with ../ paths, which I would not recommend — solution files that reach outside their own directory are a maintenance smell.
Recommendation: Option B with the targeted second render. Effort estimate: small on the CLI side (~1 new file + wiring + tests), plus one template-library release. No changes to flag surface, result JSON schema, or the template.Create contract beyond tolerating a new set value.