Search code examples
visual-studiotemplatest4template-enginet4-toolbox

Invoking Text Transformation in VS Extension


I want to create a Visual Studio Item Template that generates an Item (for eg. custom .aspx page) in the solution by executing T4 Template while adding it to the solution. For this I am using this link : http://msdn.microsoft.com/en-us/library/gg586947.aspx Can anyone tell me how to get a Service Provider, which is mentioned in the code in above link. To solve this I wrote :

EnvDTE.DTE dte = (EnvDTE.DTE)Package.GetGlobalService(typeof(EnvDTE.DTE)); // Get a service provider – how you do this depends on the context:

IServiceProvider serviceProvider = new Microsoft.VisualStudio.Shell.ServiceProvider(dte as Microsoft.VisualStudio.OLE.Interop.IServiceProvider);

But Its giving me an arguement null exception error, because variable dte remains null. Why is it null? I don't know whether I am doing it right or wrong. Please suggest how do I implement serviceprovider given in the code in above link so that I could move ahead. If possible please provide me a code example.

Please suggest,

Thanks, Mayur


Solution

  • You should just be able to directly query for STextTemplating using GetGlobalService in Visual Studio 2010.