Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

T4ParameterValues Support #11

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

SmithPlatts
Copy link

Reason for PR

Wanting to move a project over from MSBuild.Full and Microsoft.TextTemplating, but needed to use T4ParameterValues.

Outline of key changes

  • Added support to T4.Build to take in one or many --variable arguments, using "Include=Value" format.
  • Added processing of passed in variables into a read-only dictionary.
  • Updated BuildTemplateGenerator to enable support for a preprocessing Func<>, which is called between input file validation, and processing of template content.
    • [Note] Due to accessibility restrictions of some of the TemplateGenerator methods, I had to pull that code into this class. Ideally, TemplateGenerator could expose these as protected/virtual, so that they can be overridden by implementers.
  • Added a guarded StringBuilder for preprocessing replacement (reduced allocations) so that we don't load up a StringBuilder, and then have it generate the same string, if there are no variables to replace.

Ancillary changes

  • build/common.targets
    • Increased the scope of Item types to search for transform files; better aligns with Microsoft.TextTemplating MSBuild.
      • Microsoft.TextTemplating.targets uses the exact list as added, and I was working on a separate project where the TT file was added as Content, not None. Given that the same Generator guard is used, this seemed safe.
  • T4.Build/.gitignore
    • Added T4.Build project-specific gitignore, which ignores any T4.Build/tools/* files.
      • I was using a Reference and direct Import from another project to test and use these changes, and needed to directory junction T4.Build/tools/ to T4.Build\bin\Debug\netcoreapp3.1\ so that the import/targets pathing aligned. Can remove if you don't like it.

Adam Smith-Platts added 3 commits April 30, 2023 21:11
… a preprocessor over the templates before calling into Mono.TextTemplating

- Added support to T4.Build to take in one or many --variable arguments, using "Include=Value" format.
- Added processing of passed in variables into a read-only dictionary.
- Updated BuildTemplateGenerator to enable support for a preprocessing Func<>, which is called between input file validation, and processing of content.
| - Due to accessibility restrictions of some of the TemplateGenerator methods, I had to pull that code into this class. Ideally TemplateGenerator should expose these as protected/virtual, so that they can be overridden in implementers.
- Added a guarded StringBuilder for preprocessing so that we don't load up a StringBuilder, and then have it generate the same string, if there are no variables to replace.
…scope of item types to search for transform files

Microsoft.TextTemplating.targets uses this exact list, and I was working on a separate project where the TT file was added as Content, not None. Given that the same Generator guard is used, this seemed safe.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant