- Install NTypewriter editor for Visual Studio
- Add template file with *.nt extension to your project
- You gain access to code model from your template by special global variable
data
. So let us iterate over every class defined in solution, and write its name to output.
{{ for class in data.Classes
class.FullName | String.Append "\r\n"
end }}
- Now it is time to decide what part of our template will be saved to a file. We do that by using capture statement
capture variableName; end
. For this example we want to generate one file with list of all classes defined in solution, thus we should use capture statement outside of the for loop.
{{ capture output
for class in data.Classes
class.FullName | String.Append "\r\n"
end
end}}
{{ capture output
for class in data.Classes
class.FullName | String.Append "\r\n"
end
end
Save output "index.txt"
}}
- If something goes wrong you can look at NTypewriter output. NTypewriter is very chatty about what is doing at the moment. Most of the errors also will appear on the VS Error List.
Options are available here:
Visual Studio :: Main menu -> Tools -> Options -> NTypeWriter -> General
General -> Preview -> IsEnabled
Preview when enabled may slow down your VS significantly.
Note Preview requires Microsoft Edge WebView2 to be installed on the machine.