Reputation: 45
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
Upvotes: 1
Views: 701
Reputation: 45
Can it be due to the different assembly versions I have used in this project. The application I am developing is in VS2010, and I tried to use the assemblies with the versions 10.0.0 and for which the RunTime version is 4.0. But there are few dlls which I couldn't find with the version 10.0.0.0 and RunTime Version as v4.0. Is it the thing which is annoying me? I tried to add new dlls with the required versions but I don't have these dlls with version 10.0 and also I didn't get it anywhere on net. If thats the reason then plz let me know where I will get those dlls...? The dlls I have used are as follows :
Microsoft.VisualStudio.OLE.Interop, vesrion : 7.1.40304.0, RunTime Version : v1.1.4322
Microsoft.VisualStudio.Shell, Version : 10.0.0.0, RunTime Version : v4.0.30319,
microsoft.visualstudio.shell.interop.8.0, Version : 8.0.0.0, RuntimeVersion : v1.1.4322
Microsoft.VisualStudio.TemplateWizardInterface, Version : 8.0.0.0, Runtime Version : v2.0.50727
Microsoft.VisualStudio.TextTemplating, Version : 9.0.0.0, Runtime Version : v2.0.50727
Microsoft.VisualStudio.TextTemplating.Interfaces.10.0, Version : 10.0.0.0, RunTime Version : v4.0.30319
Microsoft.VisualStudio.TextTemplating.VSHost.10.0, Version : 10.0.0.0, RunTime Version : v4.0.30319
Please suggest...
Upvotes: 0
Reputation: 6606
You should just be able to directly query for STextTemplating using GetGlobalService in Visual Studio 2010.
Upvotes: 1