jaffa
jaffa

Reputation: 27350

Get all assemblies from a solution when using t4 templates, not the current executing assembly

I'm using T4 templates to try and output all the assemblies used in my solution. However, in the .tt file, all the loaded assemblies have nothing to do with the parent project or solution as I presume these are all the assemblies required by the build manager.

I would like to iterate through all the assemblies in the current solution when the .tt file is parsed. Is there any way to achieve this?

Upvotes: 0

Views: 705

Answers (1)

Jon
Jon

Reputation: 437386

Unfortunately, reflecting on assemblies in your current solution from within T4 will not work. This is because assemblies, once loaded, cannot be unloaded unless and until you unload the whole AppDomain. In practice this means that after the first time you reflect the assemblies will become write-locked and you will only be able to unlock them by exiting Visual Studio.

One possible workaround would be to use Introspection instead of reflection, as described here (includes example code).

Upvotes: 2

Related Questions