Quantcast
Channel: Visual Studio Integrate forum
Viewing all articles
Browse latest Browse all 4410

Using extension methods from a separate class library in T4

$
0
0

I created a class library with extension methods for working with EnvDTE objects. An example extension method is:

namespace EnvDTE.Extensions{    public static class DTEExtensions    {        public static Project CurrentProject (this DTE dte)        {            return dte.ActiveDocument.ProjectItem.ContainingProject;        }    }}


when I attempt to use the extension method in my T4 file:

<#@ template debug="false" hostspecific="true" language="C#" #><#@ assembly name="EnvDTE" #><#@ assembly name = "$(SolutionDir)..\..\Windows\EnvDTE.Extensions\EnvDTE.Extensions\bin\Debug\EnvDTE.Extensions.dll" #><#@ assembly name = "System.Core" #><#@ import namespace="EnvDTE" #><#@ import namespace="EnvDTE.Extensions" #><#@ import namespace="System.IO" #><#@ import namespace="System.Linq" #><#@ import namespace="System.Text" #><#@ import namespace="System.Collections.Generic" #><#@ output extension=".cs" #><#    var serviceProvider = (IServiceProvider)this.Host;    var dte = serviceProvider.GetService(typeof(DTE)) as DTE;     var project = dte.CurrentProject();#>namespace <#= project.Properties.Item("DefaultNamespace").Value #>{}


I get the following exception:

Severity    Code    Description Project File    LineError       Running transformation: System.Runtime.Remoting.RemotingException: Cannot load type 'EnvDTE._DTE, EnvDTE.Extensions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.Server stack trace:    at System.Runtime.Remoting.Messaging.MethodCall.ResolveMethod(Boolean bThrowIfNotResolved)   at System.Runtime.Remoting.Messaging.MethodCall..ctor(SmuggledMethodCallMessage smuggledMsg, ArrayList deserializedArgs)   at System.Runtime.Remoting.Channels.CrossAppDomainSink.DoDispatch(Byte[] reqStmBuff, SmuggledMethodCallMessage smuggledMcm, SmuggledMethodReturnMessage& smuggledMrm)   at System.Runtime.Remoting.Channels.CrossAppDomainSink.DoTransitionDispatchCallback(Object[] args)Exception rethrown at [0]:    at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)   at EnvDTE._DTE.get_ActiveDocument()   at EnvDTE.Extensions.DTEExtensions.CurrentProject(DTE dte) in D:\Users\Adaptive\Projects\Windows\EnvDTE.Extensions\EnvDTE.Extensions\DTEExtensions.cs:line 13   at Microsoft.VisualStudio.TextTemplating0BE14095FFF8852C1DA8AAA0F831675849ECBB71E2A8B8BA2027BD64107CEDE73824E8CF863A0048B6B5FF80E64944B13E838B3338BD67CA7B6A2CF9BB4BD07C.GeneratedTextTransformation.TransformText() TicketTracker   D:\Users\Adaptive\Projects\Universal\TicketTracker\TicketTracker\Models\HoursModel.tt   1


Any idea what I'm doing wrong here? It appears the transformation engine is looking for types in the wrong library. I know I could create a collection of my extension methods by importing various T4 files, but I prefer a class library if I can make it work.


Viewing all articles
Browse latest Browse all 4410

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>