A Visual Studio extension that invokes a dotnet tool as a code generator, piping a file in the solution as input to the tool and piping the output to a new file in the solution. This is structurally identical to other "designer-time" and "code-behind" file pairs in the solution.
Adding code generators to Visual Studio often involve authoring, installing, and maintaining an extension for each code generator. Creating these extensions require significant overhead, especially if the the extension merely wraps an existing command line utility, such as a dotnet tool. The extension from this repository facilitates code generation via dotnet tools, which are easily consumed via NuGet packages.
- This extension is installed in a compatible version of Visual Studio
- The dotnet tool you want to use is installed, either globally or locally
-
Add a new file to the project to represent the design-time file (i.e. the input to the dotnet tool)
-
Open its file properties and set "Custom Tool" to
Jmg.CodeGen
-
Create a file called
.codegen.yml
in the same directory -
Insert this YAML document:
files: - file: YourDesignerFileName.dat tool: sometoolname extension: .cs
-
Replace the
file
value with the name of the design-time. -
Replace the
tool
value with the command from your dotnet tool. -
Replace the
extension
value with the file extension that should be generated. -
Every subsequent update to the design-time file will invoke code generation.
See my other repo, Parsnip
, for an example of a dotnet tool that generates a parser from a grammar file, using this extension to facilitate the code generation in Visual Studio.