1

Is it possible to have a T4 template that automatically picks up all assembly references (and their dependencies) of the parent project?

All examples I have seen use <#@ assembly #> or <#@ VolatileAssembly #> to manually define references, so for example I end up having to reference System.Core both in the project and the template. I want to avoid this duplication: I only want to define references in the project, not the template.

This should also add a reference to the project itself, allow referencing additional assemblies in the template, and shadow copy whenever necessary to avoid assembly locking.

It seems this was possible before VS2010, is it possible to re-implement/restore that behavior?

Community
  • 1
  • 1
Mauricio Scheffer
  • 98,863
  • 23
  • 192
  • 275

1 Answers1

1

T4 did indeed pick up the project dependencies before VS2010. We deliberately chose to separate out design-time references from runtime references in order to separate those concerns and better support using .Net 4.0 in templates even if they were being used to generate code for a .Net 2.0 project.

You could do something similar to pre-VS2010 by making a custom directive processor that used the Host as a ServiceProvider to get the DTE and then walked the solution/projects to find their references. It would be quite a bit of work though.

I'm interested to know what ties the dependencies of your project to the dependencies that your template needs. For example, a project that uses WinForms doesn't usually need WinForms in its template code. Basics like System.Core are usually in both, but that shared set doesn't often seem to be large, so the duplication is not a significant problem.

Do you have a large shared set?

GarethJ
  • 6,496
  • 32
  • 42
  • I'm trying to build a lightweight DSL (the textual type, not the graphical type used in the SDK DSL tools) using T4, and I have to analyze and manipulate the types of the expressions being used (which can be any type referenced in the project), so yes, it's a large shared set... – Mauricio Scheffer Jan 26 '11 at 02:36