使用 t4 模板时从解决方案获取所有程序集,而不是当前执行的程序集
我正在使用 T4 模板来尝试输出我的解决方案中使用的所有程序集。但是,在 .tt 文件中,所有加载的程序集与父项目或解决方案无关,因为我认为这些是构建管理器所需的所有程序集。
我想在解析 .tt 文件时迭代当前解决方案中的所有程序集。 有什么办法可以实现这一点吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不幸的是,从 T4 中反映当前解决方案中的程序集将不起作用。这是因为程序集一旦加载,就无法卸载,除非卸载整个 AppDomain。实际上,这意味着在您第一次反映后,程序集将变为写锁定,并且您只能通过退出 Visual Studio 来解锁它们。
一种可能的解决方法是使用内省而不是反射,如所述 此处(包括示例代码)。
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).