Cohesive.CodeGen.Cli
0.1.0-alpha.4
dotnet add package Cohesive.CodeGen.Cli --version 0.1.0-alpha.4
NuGet\Install-Package Cohesive.CodeGen.Cli -Version 0.1.0-alpha.4
<PackageReference Include="Cohesive.CodeGen.Cli" Version="0.1.0-alpha.4" />
<PackageVersion Include="Cohesive.CodeGen.Cli" Version="0.1.0-alpha.4" />
<PackageReference Include="Cohesive.CodeGen.Cli" />
paket add Cohesive.CodeGen.Cli --version 0.1.0-alpha.4
#r "nuget: Cohesive.CodeGen.Cli, 0.1.0-alpha.4"
#:package Cohesive.CodeGen.Cli@0.1.0-alpha.4
#addin nuget:?package=Cohesive.CodeGen.Cli&version=0.1.0-alpha.4&prerelease
#tool nuget:?package=Cohesive.CodeGen.Cli&version=0.1.0-alpha.4&prerelease
Cohesive.CodeGen.Cli
Cohesive.CodeGen.Cli is the build-facing entry point for Cohesive code generation.
Install
dotnet add package Cohesive.CodeGen.Cli
Its current job is:
- load a compiled contracts assembly
- project exported CLR contract types into Cohesive shape IR
- emit TypeScript, OpenAPI, and GraphQL artifacts into a target directory under a frontend app
The CLI is designed for build integration, idempotent writes, and incremental frontend workflows.
Current Scope
Implemented today:
shapes→ TypeScript declarations generated from exported CLR contractsapis→ TypeScript client functions generated from exportedApiDefinitionmembersopenapi→ OpenAPI 3.1 JSON generated from exportedApiDefinitionmembersgraphql→ GraphQL SDL and introspection JSON generated from exportedApiDefinitionmembers
Reserved for follow-on work:
transitionsprocessesinvariants
Usage
dotnet exec path/to/cohesive-codegen.dll \
--contracts path/to/MyApp.Contracts.dll \
--out path/to/generated \
--emit shapes,apis,openapi,graphql \
--module myapp
Equivalent conceptual tool form:
cohesive-codegen \
--contracts path/to/MyApp.Api.Contracts.dll \
--out path/to/generated \
--emit shapes,apis,openapi,graphql \
--module myapp
Arguments
--contractsPath to the compiled .NET assembly that contains exported API contract types.--outOutput directory for generated artifacts. For React + Vite this should usually be a folder undersrc/generated.--emitComma-separated list of artifact kinds. Todayshapes,apis,openapi, andgraphqlare implemented.--moduleLogical module name used in output filenames, for examplemyapp.shapes.generated.ts.--helpPrints CLI usage.
Output Behavior
For --emit shapes,apis,openapi,graphql, the CLI currently writes:
<module>.shapes.generated.ts<module>.api.generated.ts<module>.openapi.generated.json<module>.graphql.generated.graphql<module>.graphql.introspection.generated.json
Example:
myapp.shapes.generated.tsmyapp.api.generated.tsmyapp.openapi.generated.jsonmyapp.graphql.generated.graphqlmyapp.graphql.introspection.generated.json
Writes are content-aware:
- if the generated content is unchanged, the file is left untouched
- if the generated content changes, the file is atomically replaced
This matters for frontend dev servers because it avoids unnecessary file watcher churn.
React / Vite Workflow
Recommended layout:
src/
MyApp.Contracts/
myapp-web/
src/
generated/
myapp.shapes.generated.ts
Recommended loop:
dotnet build src/MyApp.Contracts/MyApp.Contracts.csprojnpm run devinside the frontend app
Because the generated file lives under the Vite app's src tree, real contract changes trigger hot reload naturally.
MSBuild Integration
The intended integration point is an AfterTargets="Build" target on the contracts project.
Typical shape:
<Target Name="GenerateTypeScriptContracts"
AfterTargets="Build"
Inputs="$(TargetPath);$(CohesiveCodeGenCliDll)"
Outputs="$(CohesiveGeneratedShapesFile)"
Condition="'$(CohesiveCodeGenEnabled)' == 'true'">
<MakeDir Directories="$(CohesiveTypeScriptOutDir)" />
<Exec Command="dotnet exec "$(CohesiveCodeGenCliDll)" --contracts "$(TargetPath)" --out "$(CohesiveTypeScriptOutDir)" --emit shapes,apis,openapi,graphql --module "$(CohesiveCodeGenModule)"" />
</Target>
Two separate mechanisms prevent rebuild churn:
- MSBuild
Inputs/Outputscan skip the target entirely when the generated file is already up to date. - The CLI itself skips rewriting the file when the generated text is identical.
Both are useful. The first avoids unnecessary process execution. The second protects correctness when the target does execute.
Type Discovery
The CLI currently:
- loads the target assembly in an isolated
AssemblyLoadContext - inspects exported public CLR types
- filters to contract-like object types with readable public instance properties
- builds a
ShapeGraph - emits TypeScript from that graph
- discovers exported public static
ApiDefinitionmembers namedDefinition,Api, orApiDefinition - emits TypeScript client functions that call an injected
httpfunction - emits OpenAPI and GraphQL schema projections from the same API definitions
This supports a POCO-first workflow while still targeting Cohesive IR internally.
Direction
The longer-term model is:
- author shapes as CLR POCOs, or directly as Cohesive IR
- project those shapes into a common IR
- emit multiple target languages from the same semantic graph
TypeScript is the first target, not the terminal abstraction.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Cohesive (>= 0.1.0-alpha.4)
- Cohesive.Adapters.GraphQL (>= 0.1.0-alpha.4)
- Cohesive.Adapters.OpenApi (>= 0.1.0-alpha.4)
- Cohesive.Adapters.TypeScript (>= 0.1.0-alpha.4)
- Cohesive.Api (>= 0.1.0-alpha.4)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.1.0-alpha.4 | 53 | 7/13/2026 |
| 0.1.0-alpha.3 | 55 | 7/8/2026 |
| 0.1.0-alpha.2 | 53 | 7/7/2026 |