简体   繁体   English

VS2022 可扩展性:如何解决“在 T4 模板执行中,‘Assembly 1’和‘Assembly2’中都存在类型‘XXX’

[英]VS2022 Extensibility: How to resolve "The type 'XXX' exists in both 'Assembly 1' and 'Assembly2' in T4 template execution

I have an extension I'm updating from VS2019 to VS2022.我有一个扩展,我正在从 VS2019 更新到 VS2022。 It's a DSL using the Modeling SDK and has code generation via T4 templates.它是使用建模 SDK 的 DSL,并通过 T4 模板生成代码。

I have it pretty much converted but, when running the T4s, I get我几乎已经转换了,但是在运行 T4s 时,我得到了

Compiling transformation: The type 'SourceControl' exists in both 'EnvDTE, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' and 'Microsoft.VisualStudio.Interop, Version=17.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
Compiling transformation: The type 'Project' exists in both 'EnvDTE, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' and 'Microsoft.VisualStudio.Interop, Version=17.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'      
Compiling transformation: The type 'Constants' exists in both 'EnvDTE, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' and 'Microsoft.VisualStudio.Interop, Version=17.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'    
Compiling transformation: The type 'ProjectItem' exists in both 'EnvDTE, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' and 'Microsoft.VisualStudio.Interop, Version=17.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'  
Compiling transformation: The type 'ProjectItems' exists in both 'EnvDTE, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' and 'Microsoft.VisualStudio.Interop, Version=17.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' 
Compiling transformation: The type 'DTE' exists in both 'EnvDTE, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' and 'Microsoft.VisualStudio.Interop, Version=17.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'          
Compiling transformation: The type 'Solution' exists in both 'EnvDTE, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' and 'Microsoft.VisualStudio.Interop, Version=17.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'     

and can't figure out how to resolve this.并且无法弄清楚如何解决这个问题。

I'm not including those assemblies in my main .tt file, nor are they referenced in my Dsl or DslPackage projects, but I understand from some other errors I had to resolve that EnvDTE8.0 and Microsoft.VisualStudio.Interop are implicitly available as part of the ambient VS2022 environment.我没有将这些程序集包含在我的主.tt文件中,也没有在我的DslDslPackage项目中引用它们,但我从其他一些错误中了解到我必须解决EnvDTE8.0Microsoft.VisualStudio.Interop隐式可用环境 VS2022 环境的一部分。 Since they're not part of my projects, I can't use the Visual Studio Alias mechanism to disambiguate.由于它们不属于我的项目,因此我无法使用 Visual Studio Alias机制来消除歧义。

I've read the other questions on SO regarding similar issues, but none of them are this problem and their solutions really don't apply.我已经阅读了关于类似问题的其他问题,但没有一个是这个问题,他们的解决方案真的不适用。

Thanks for any help or direction anyone can give.感谢任何人可以提供的任何帮助或指导。

I ran into a similar issue today with my T4 templates.今天我的 T4 模板遇到了类似的问题。 After looking at your post and noodling on it for a couple of minutes I tried the following在看了你的帖子并在上面闲逛了几分钟后,我尝试了以下操作

I found the file that was adding the EnvDTE assembly我找到了添加EnvDTE程序集的文件

<#@ assembly name="EnvDTE"#>

and changed it to并将其更改为

<#@ assembly name="Microsoft.VisualStudio.Interop"#>

and that resolved my issue.这解决了我的问题。

try to delete the EnvDTE assembly.尝试删除 EnvDTE 程序集。

<#@ assembly name="EnvDTE"#>

Craig's solution didn't quite work for me.克雷格的解决方案并不适合我。 I found that this issue was raised in T4MVC's github here https://github.com/T4MVC/T4MVC/issues/136#issuecomment-1089244574我发现这个问题是在 T4MVC 的 github 中提出的https://github.com/T4MVC/T4MVC/issues/136#issuecomment-1089244574

The suggested solution which worked for me was:对我有用的建议解决方案是:

I fixed this by removing the assembly imports of EnvDTE, EnvDTE80, and Microsoft.VisualStudio.Shell.Interop.我通过删除 EnvDTE、EnvDTE80 和 Microsoft.VisualStudio.Shell.Interop 的程序集导入来解决此问题。 (The namespace imports are still necessary.) (命名空间导入仍然是必需的。)

This is clearly similar to the other suggestions but I think it's slightly different since those didn't seem to work for me, or I misunderstood them.这显然与其他建议相似,但我认为它略有不同,因为这些似乎对我不起作用,或者我误解了它们。 To fix it all I did was delete the three suggested import lines.为了解决这个问题,我所做的只是删除了三个建议的导入行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM