16

I'm using EnvDTE to do some code generation within my T4 Templates.

I have the code working correctly in Visual Studio 2010, however I've just started using Visual Studio 2012 and now when I try to run my templates I get the following error

Compiling transformation: Metadata file 'EnvDTE.dll' could not be found 

I don't actually have a reference to EnvDTE in my project as its a Silverlight class library and I wasn't able to add the DLL, however it finds the DLL somehow.

I'm not sure what is difference is between 10 and 12 to cause this.

The following are my imports and assembly definitions from the start of my ttinclude file.

<#@ template debug="true" hostSpecific="true" #>
<#@ output extension=".generated.cs" #>
<#@ Assembly Name="EnvDTE.dll" #>
<#@ Assembly Name="System.Data" #>
<#@ import namespace="EnvDTE" #>
<#@ import namespace="System.Data" #>
<#@ import namespace="System.Data.SqlClient" #>
<#@ import namespace="System.IO" #>
<#@ import namespace="System.Text.RegularExpressions" #>

Is there anything I have to do differently to get it working for Visual Studio 2012

Midimatt
  • 1,114
  • 2
  • 17
  • 35
  • `<#@ Assembly Name="EnvDTE.dll" #>` Also, you'll want to debug this using the [Fusion log viewer.](http://msdn.microsoft.com/en-us/library/e74a18c4.aspx) Just make sure to run it as admin, turn on the log, and reboot before attempting to debug. You'll see where the CLR is looking for the assembly, and what version, and from there determine why it isn't being found (if you even have it installed). –  Aug 29 '12 at 14:12
  • Nothing shows up for EnvDTE when logging using Fusion, i've definitely got EnvDTE installed as part of 2010 and 2008, there isn't a new version for 2012 – Midimatt Aug 29 '12 at 15:01
  • 1
    *Nothing*? That seems odd. For S&Gs, try `<#@ Assembly Name="C:\Program Files (x86)\Common Files\microsoft shared\MSEnv\PublicAssemblies\envdte.dll" #>` (assuming you can find EnvDTE there) –  Aug 29 '12 at 15:50
  • Thanks Will, giving it the full path worked. Not really sure why I didn't think of that first to be honest. – Midimatt Aug 29 '12 at 15:59

3 Answers3

17

It appears that VS12 can't figure out where EnvDTE is. Its odd that (as you mentioned in a comment) fusion didn't pick that up. Perhaps it did, but you weren't reading it correctly?

As an aside, when the fusion log lets you down, its time to break out Process Monitor when you can't figure out why an application can't find something that should be there.

You can give a full path for assembly references in T4 templates. In your case, it would be

<#@ Assembly Name="C:\Program Files (x86)\Common Files\microsoft shared\MSEnv\PublicAssemblies\envdte.dll" #>

(assuming you have EnvDTE in the correct spot). I wouldn't consider this a true solution, and would open a Connect issue with MS about this. Seems like a bug.

  • 1
    Our plan is to move away from EnvDTE eventually so for now this should be enough. Thank you – Midimatt Aug 31 '12 at 08:39
  • not helpful if you need to have these references available as part of a subversion project – DevDave Jul 24 '13 at 11:13
  • is there a solution that work in machines with 32bit and 64bit? Your solution only work for 64 bit – Pedro Rainho Dec 12 '13 at 14:12
  • 1
    @PedroRainho: Uh, remove ` (x86)` from the path? Just search for the location of the envdte.dll you want to reference, copy the path, and use that. –  Dec 12 '13 at 16:29
  • I'm looking for a solution that works on solution that work in machines with 32bit and 64bit machines. on 64 bits the file is located here: C:\Program Files (x86)\Common Files\microsoft shared\MSEnv\PublicAssemblies\envdte.dll and on 32bit the file is located here: C:\Program Files\Common Files\microsoft shared\MSEnv\PublicAssemblies\envdte.dll. As you can imagine I can't reference both assemblies – Pedro Rainho Dec 13 '13 at 19:53
  • 1
    @PedroRainho: Tried using preprocessor directives? –  Dec 13 '13 at 21:20
16

After stumbling about the same error i searched a little deeper and found this Microsoft Connect entry.

To fix the problem simply remove the .dll from the assembly name and it works as expected:

<#@ Assembly Name="EnvDTE" #>

Also ensure that the EnvDTE assembly is located within the GAC under C:\Windows\assembly. This will normally automaticaly happen when you install Visual Studio on a machine.

Example

Here is an example that should work out of the box:

<#@ template language="C#" debug="true" hostSpecific="true" #>
<#@ output extension=".txt" #>
<#@ Assembly Name="System.Core" #>
<#@ Assembly Name="System.Design" #>
<#@ Assembly Name="System.Drawing" #>
<#@ Assembly Name="System.Windows.Forms" #>
<#@ Assembly Name="EnvDTE" #>
<#@ import namespace="System" #>
<#@ import namespace="System.CodeDom.Compiler" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ import namespace="System.Drawing" #>
<#@ import namespace="System.IO" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Resources" #>
<#@ import namespace="System.Resources.Tools" #>
<#@ import namespace="EnvDTE" #>
<#@ import namespace="Microsoft.CSharp" #>

All projects currently available within this solution:
<#
    //System.Diagnostics.Debugger.Launch();

    EnvDTE.DTE dte = (EnvDTE.DTE)((IServiceProvider)this.Host)
                       .GetService(typeof(EnvDTE.DTE));

    EnvDTE.Projects projects = dte.Solution.Projects;

    foreach (EnvDTE.Project project in projects)
    {
#>
        <#= project.Name #>
<#
    }
#>

This file was generated at: <#= System.DateTime.Now.ToShortDateString() #> <#= DateTime.Now.ToLongTimeString() #>
Oliver
  • 43,366
  • 8
  • 94
  • 151
  • Yep, had this inside an include file. Removing the extension worked. +1. – Adam Naylor Aug 27 '13 at 15:01
  • that doesn't work. I've tested and this is the result error CS0006: Metadata file 'EnvDTE' could not be found – Pedro Rainho Dec 12 '13 at 14:13
  • @PedroRainho: Just added an example that works without any problems under VS2012. Maybe it helps you to find the error. – Oliver Dec 13 '13 at 07:30
  • 1
    Ok, your example works because, you have EnvDte in the GAC. But out of the box without moving this assembly to the gac, it doesn't work. I can't move envDte to the gac because I've dozens of developers using T4 and I will not do that move in all machines. – Pedro Rainho Dec 13 '13 at 19:51
  • @PedroRainho: Which kind of tool do you use for coding? If you use Visual Studio and its default installer it will automatically put the EnvDTE into the GAC when you install it. – Oliver Dec 16 '13 at 07:15
0

I was facing the issue related to EnvDTE80 on my visual studio 2019 while loading an application. Error displayed the following message: "Reference.svcmap: Could not load file or assembly "'EnvDTE," Version=8.0.0.0, Culture=neutral..."

I cleaned the solution and installed the nuget package for version 8.0.0.0. Then rebuilt the solution. In that way my visual studio was able to load the application.