开发者

Automatically getting all assembly references in T4

开发者 https://www.devze.com 2023-02-06 12:23 出处:网络
Is it possible to have a T4 template that automatically picks up all assembly references (and their dependencies) of the parent project?

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

A开发者_Go百科ll 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?


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?

0

精彩评论

暂无评论...
验证码 换一张
取 消