简体   繁体   中英

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. It's a DSL using the Modeling SDK and has code generation via T4 templates.

I have it pretty much converted but, when running the T4s, I get

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. Since they're not part of my projects, I can't use the Visual Studio Alias mechanism to disambiguate.

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. 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

<#@ assembly name="EnvDTE"#>

and changed it to

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

and that resolved my issue.

try to delete the EnvDTE assembly.

<#@ 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

The suggested solution which worked for me was:

I fixed this by removing the assembly imports of EnvDTE, EnvDTE80, and 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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