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

#line annotations no longer generated with relative paths with dotnet-t4 #152

Closed
mwadams opened this issue Mar 1, 2023 · 3 comments · Fixed by #154
Closed

#line annotations no longer generated with relative paths with dotnet-t4 #152

mwadams opened this issue Mar 1, 2023 · 3 comments · Fixed by #154

Comments

@mwadams
Copy link
Contributor

mwadams commented Mar 1, 2023

In our JSON Schema code generation project, we use T4 to generate code at build time.

There is a fair bit of code to generate, and we do this "one time" and commit the results to our repo, rather than running the template generation with every build, and check in the product.

We are currently running T4 text template processor version 2.3.1+932110915c from an orchestrating batch file which looks like this:

REM Runs all the template build commands
cd Corvus.Json.CodeGeneration.6\Corvus.Json.CodeGeneration.Draft6
start cmd.exe /C BuildTemplates.cmd
cd ..\..\Corvus.Json.CodeGeneration.7\Corvus.Json.CodeGeneration.Draft7
start cmd.exe /C BuildTemplates.cmd
cd ..\..\Corvus.Json.CodeGeneration.201909\Corvus.Json.CodeGeneration.Draft201909
start cmd.exe /C BuildTemplates.cmd
cd ..\..\Corvus.Json.CodeGeneration.202012\Corvus.Json.CodeGeneration.Draft202012
start cmd.exe /C BuildTemplates.cmd
cd ..\..\Corvus.Json.ExtendedTypes\Corvus.Json
start cmd.exe /C BuildTemplates.cmd
cd ..\..

The individual batch files contain a set of commands that look like this:

t4 -o Generators/CodeGenerator.Array.Add.cs -c Corvus.Json.CodeGeneration.Generators.Draft6.CodeGeneratorArrayAdd ../../Corvus.Json.CodeGeneration.Abstractions/SharedTemplates/CodeGenerator.Array.Add.tt

With previous versions of the dotnet-t4 tool (prior to 2.3.0), we used to get relative paths in the #line annotations.

#line 123 "../../Corvus.Json.CodeGeneration.Abstractions/SharedTemplates/CodeGenerator.Array.Add.tt"

But in the 2.3.0 and 2.3.1 versions we see

#line 123 "C:\Users\BLAH\source\repos\Corvus.JsonSchema\Solutions\Corvus.Json.CodeGeneration.Abstractions\SharedTemplates\CodeGenerator.Array.Add.tt"

This is a problem for our scenario because it ties those annotations to the machine on which it was generated [and incidentally generates hundreds of spurious file changes when there are only small numbers of actual changes]

@mwadams
Copy link
Contributor Author

mwadams commented Mar 1, 2023

I can see that this is because there is a new option UseRelativeLinePragmas in Mono.TextTemplating/Mono.TextTemplating/TemplateGenerator.cs

However this defaults to false when the original behaviour was to default to true.

@mwadams
Copy link
Contributor Author

mwadams commented Mar 1, 2023

There doesn't seem to be any way of controlling this from the dotnet-t4 tool.

@mwadams mwadams changed the title #line annotations no longer generated with relative paths #line annotations no longer generated with relative paths with dotnet-t4 Mar 1, 2023
@mwadams
Copy link
Contributor Author

mwadams commented Mar 1, 2023

A workaround is to install version 2.2.1+650c1854cb explicitly.

mwadams added a commit to endjin/t4 that referenced this issue Apr 19, 2023

Unverified

This user has not yet uploaded their public signing key.
…nerator.

This enables us to (optionally) restore what was the default behaviour prior to v2.3.0.

This commit resolves mono#152
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 a pull request may close this issue.

1 participant