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

When using output extension directive with .gen.cs, the final file becomes xxx.gen.gen.cs #7

Open
scottbilas opened this issue Aug 8, 2022 · 2 comments

Comments

@scottbilas
Copy link

Problem

I have this directive in my .tt file:

<#@ output extension=".gen.cs" #>

When using VS or Rider's built-in text templating, this produces an output <filename>.gen.cs. But when using T4.Build, it outputs <filename>.gen.gen.cs.

Solution (my guess)

I don't know how to debug an msbuild task, but looking through the code it appears this is caused by (T4.Build) BuildTemplateGenerator.OutputFile doing a Path.ChangeExtension before (Mono.TextTemplating) TemplateGenerator.SetFileExtension does the same thing.

When using an ordinary extension (.xyz) the double-call doesn't change anything. When using a doubled extension (.xyz.abc) the "sub"-extension gets doubled up, resulting in the <filename>.gen.gen.cs I mentioned above.

My guess on a fix would be, within BuildTemplateGenerator.OutputFile, to only change extension if no output directive is found.

@xavierjohn
Copy link

I ran into the same problem
<#@ output extension="g.cs" #>
becomes
g.g.cs

@xavierjohn
Copy link

My simple workaround is to add the suffix to tt file

So foo.tt becomes foo.g.tt which will generate foo.g.cs and I can add *.g.cs to .gitignore

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

No branches or pull requests

2 participants