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

Visual Studio 2010 variables not recognized when using ITextTemplating ProcessTemplate from within an AddIn

$
0
0

I've created a Visual Studio 2010 AddIn (C#) to automate processing several T4 templates within a solution.  The problem I'm seeing is that if I manually Run Custom Tool from within the IDE on any of the templates they work fine, BUT if I run them programmatically from within an AddIn then my assembly references that are using Visual Studio variables such as $(SolutionDir) fail with an Exception.  The Exception is:

The host threw an exception while trying to resolve the assembly reference 'S(SolutionDir)\bin\Debug\myassembly.dll'. The transformation will not be run.  The following Exception was thrown: System.IO.FileLoadException: The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047) at System.Reflection.AssemblyName.nInit(RuntimeAssembly& assembly, Boolean forIntrospection, Boolean raiseResolveEvent)
   at System.Reflection.AssemblyName..ctor(String assemblyName)
   at Microsoft.VisualStudio.TextTemplating.GlobalAssemblyCacheHelper.GetLocation(String strongName)
   at Microsoft.VisualStudio.TextTemplating.VSHost.TextTemplatingService.ResolveAssemblyReference(String assemblyReference)
   at Microsoft.VisualStudio.TextTemplating.Engine.ResolveAssemblyReferences(ITextTemplatingEngineHost host, TemplateProcessingSession session)

The code I'm using within the AddIn to programatically process the templates is (m_applicationObject is the application object passed into OnConnection and solutionName and ttGenerationFile are variables I pass in):

 

m_applicationObject.Solution.Open(solutionName);

TextReader tr = newStreamReader(ttGenerationFile);

 

 

string content = tr.ReadToEnd();

 

 

IServiceProvider serviceProvider = newServiceProvider((Microsoft.VisualStudio.OLE.Interop.IServiceProvider)m_applicationObject.DTE);

 

 

ITextTemplating tt = serviceProvider.GetService(typeof(STextTemplating))asITextTemplating;

tt.ProcessTemplate(ttGenerationFile, content,

 

this,null);

If I hardcode the paths in the assemble reference within the template like so it works:

<#@

 

assemblyname="c:\library\bin\Debug\myassembly.dll" #>

So my Question is why does this work manuall from within the IDE/Solution, but not programatically?

Thanks


Viewing all articles
Browse latest Browse all 4410

Trending Articles



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