DotGram.Cli
0.3.0
dotnet tool install --global DotGram.Cli --version 0.3.0
dotnet new tool-manifest
dotnet tool install --local DotGram.Cli --version 0.3.0
#tool dotnet:?package=DotGram.Cli&version=0.3.0
nuke :add-package DotGram.Cli --version 0.3.0
DotGram.Cli
dotnet dotgram runs the DotGram parser generator outside the
build and writes the C# files a build would have generated.
A project either references the DotGram package and generates in its build, or has its parsers
generated by DotGram.Cli and committed — never both: the build would generate the same types again
(CS0102/CS0111 on every member).
A grammar of hundreds of rules takes seconds to generate, and a cold build or a CI run pays that every time. Keep a large grammar in a project of its own first, so that only the projects that change it pay. When that is not enough, the same generator can run outside the build:
dotnet new tool-manifest
dotnet tool install DotGram.Cli
dotnet dotgram generate src/Grammars/Grammars.csproj -o src/Grammars/Generated
The project then compiles the files in Generated/ like any other C# and drops its DotGram reference.
A single grammar needs no project: dotnet dotgram generate calc.gram -o out --namespace Demo --option Lexical=true
writes the host class from the options, the [Gram] properties being --option Name=value.
What it promises. generate writes the files DotGram would generate in dotnet build of the project
(configuration Release unless --configuration says otherwise), byte for byte, in the encoding the compiler
writes them (UTF-8 with a byte order mark), with the tool's DotGram, for a restored project, built with the
same SDK, whose own targets do not change the compiler's inputs outside the IDE's design-time pass. A
difference on a project inside that condition, which every ordinary SDK-style project is, is a defect in
the tool: report it. Two differences are by design: #line paths are relative to the output folder
(--line-paths absolute gives the build's text), and the generation report files
(DotGramReportGeneration) are not written. The EmbeddedAttribute definition is the compiler's text and
may differ in line endings from your SDK's. The diagnostics of DotGram itself are shown at the severities the
build gives them, and an error among them stops the run.
What it does not do. It does not compile your project and does not tell you whether it builds: errors in
grammar actions, in the generated parser or anywhere else in the project show when your build compiles the
files. It reports the errors in your own sources that it sees, at the compiler's default severities, and does
not check the project as a whole. It runs what an IDE runs when it opens the project — MSBuild's Compile
target with the compiler skipped, as a design-time build — so a custom target that does not skip
design-time builds runs too, and one that follows the compiler finds no new assembly. It does not restore:
after changing package references, run dotnet restore first. When this is not good enough, build with
EmitCompilerGeneratedFiles=true and copy the generated files.
It reads a project with .NET SDK 8.0.100 or newer, and generates only where that SDK's compiler
can run DotGram (SDK 9.0.300 or newer for this version); a .gram input needs no SDK compiler.
Keeping it current. Nothing in the build notices that a grammar changed: run the command again after
editing a grammar, or a type it builds. Keep the arguments in a response file (dotnet dotgram generate @grammars.rsp) so that every run uses the same ones, and check in CI that the committed files are current:
run the command, then fail if git status --porcelain -- src/Grammars/Generated prints anything. A
src/Grammars/Generated/** -text line in the repository's .gitattributes keeps the files as the generator
writes them: the folder's path from the root, since a bare Generated/** matches only a folder beside the
.gitattributes (the tool prints the line for its folder). It prints
the GRAM diagnostics; the editor does not show them for a project that no longer references the package, so
write the grammar with the package and move to the tool when it is done.
dotnet dotgram --help lists every option and exit code, and dotnet dotgram --skill prints the guide for
coding agents. The reference is docs/cli.md.
Options
| Option | Input | What it does |
|---|---|---|
-o, --output <dir> |
both | where the files go (required); nothing else in the folder is touched |
--framework <tfm> |
both | one framework only: for a project, one of its target frameworks (default: each of them); for a .gram, netstandard2.0, or net8.0 or later, a framework later than net10.0 compiled against net10.0's references (default: net10.0) |
--configuration <name> |
project | the project's configuration (default Release) |
--line-paths relative\|absolute |
both | #line paths relative to the output folder (default), or as a build writes them |
--allow-unresolved |
both | generate even where the project's code has errors (reported as warnings) |
--verbose |
both | print the stack trace of a failure inside the generator |
--reference <file.dll\|dir> |
.gram |
an assembly the grammar's types come from (every *.dll of a directory) |
--package <Name>@<Version> |
.gram |
a package's assemblies, from the global packages folder |
--define <SYMBOL> |
.gram |
a preprocessor symbol, beside the framework's; several in one value, separated by ; or , |
--langversion <version> |
.gram |
the C# version (default: the SDK's for the framework) |
--namespace <Ns> |
.gram |
the host's namespace (default: none) |
--class <Name> |
.gram |
the host's name (default: the file's name) |
--public |
.gram |
a public host (default: internal) |
--option <Name>=<value> |
.gram |
a [Gram] property: Lexical=true, Carrier=Immediate, LocationType=My.ISpan, Name=Fast, TargetMethodPartSize=200, … |
--sources <file.cs\|glob> |
.gram |
C# the grammar builds, and a partial host with the members its hooks call (no [Gram] on it) |
--help, -h, -? |
print the help | |
--version |
print the versions | |
--skill |
print the guide for agents |
-- ends the options: every argument after it is the input, a dash in front or not. An option of a .gram input given
with a project is a usage error, not ignored.
Exit codes: 0 generated; 2 grammar errors (nothing written), unless every one is GRAM3004 (a type a grammar names is not in view), which exits 3; 3 usage, input or output, a project not restored, MSBuild failing for a framework, a generator that will not load, an error the project's build would report too, frameworks that generate different files.
MIT. The files the tool writes may be used under terms of
your choice, without carrying the notice: the grant is in licenses/LICENSE-GENERATED-CODE in this package.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. 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. |
This package has no dependencies.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.3.0 | 106 | 11/15/2026 |
New in 0.3.0: dotnet dotgram generate writes the parsers a build would generate, for a project (as its own build gives the compiler its inputs) or for one .gram file, so that the project compiles them and does not reference the DotGram package. For large grammars, whose generation shows in a cold build. The files are byte for byte what DotGram writes in dotnet build of the project, for a restored project built with the same SDK, apart from relative #line paths (--line-paths absolute for the build's), no generation report files, and the line endings of the EmbeddedAttribute definition. Reads a project with .NET SDK 8.0.100 or newer, and generates only where that SDK's compiler can run DotGram (SDK 9.0.300 or newer for this version); a .gram input needs no SDK compiler; runs on .NET 8 and later, on the newest runtime installed. dotnet dotgram --skill prints the guide for coding agents; docs/cli.md in the repository is the reference. The code it writes may be used on terms of your choice: the grant is licenses/LICENSE-GENERATED-CODE, in this package.