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

How to manually add dependencies to a T4 template on a .proj file? #195

Open
Pxtl opened this issue Oct 28, 2024 · 2 comments
Open

How to manually add dependencies to a T4 template on a .proj file? #195

Pxtl opened this issue Oct 28, 2024 · 2 comments
Labels

Comments

@Pxtl
Copy link

Pxtl commented Oct 28, 2024

I'm trying to get T4 templates compiling on build, but they have xml-based dependencies. I see that the TemplateBuildState.TransformTemplate objects do keep a list of dependencies that get checked as part of the Last Modified Date calculation business, but I can't find any documented API to notify the build system that my template has an external dependency. Is there any way to do that?

Thanks.

@mhutch
Copy link
Member

mhutch commented Nov 15, 2024

There isn't currently a way but we could definitely add one. Probably AdditionalDependencies item metadata with a semicolon-separated list of absolute or project-relative paths?

@mhutch mhutch added the feature label Nov 15, 2024
@Pxtl
Copy link
Author

Pxtl commented Nov 15, 2024

That would be good. I dug into the code of T4.Build but on this one, it had code to treat the #@Include directives as inputs to the target so it could be re-run if they changed when skipUpToDate was enabled -- I don't know if your project does same. If that was the case, a way to opt into this for non-include directives using a custom directive would be the gold-plated version of this.

Something like

<#@ IncludeAdditionalDependency Processor="T4.BuildTools.CustomDirectives"  Path="../../somefile.xml" AsStreamVariable="myXmlStream" #>

<#
var myXDoc = XDocument.Load(myXmlStream);
foreach(var xEl in myXDoc.Root.Elements())
{
#>
   do stuff with <#= xEl.Value #>
<#
{
#>

Then the user doesn't have to duplicate their reference to the file in both the .csproj and the .tt. But I think you still might have to do something with adding it as an UpToDateCheckInput or whatever in some circumstances, I'm not sure... I've been trying to learn about msbuild's xml language but it's strange and feels more difficult than it needs to be.

Of course, then you get into questions about wildcards or referencing a whole tree of directories or whatever instead of a single file. For me a single-file is all I need for my use-case though.

Either way, any way to flag a file as a non-T4 dependency for the T4 template for up-to-date checking would be great, I'm just gold-plating.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants