I'm trying to do some experiments with generating code from VS2012 projects but I cannot make this piece of t4 code to work
var project = VisualStudioHelper.CurrentProject;
since VisualStudioHelper cannot be found.
What should I install/include in my t4 for making VisualStudioHelper available?
VisualStudioHelper is a custom class from Tangible T4 Editor.
In order to use this class, install Tangible T4 Editor for your Visual Studio and then:
<#@ include file="VisualStudioHelper.ttinclude" #>
What is VisualStudioHelper
? This seems to be a custom thing and not something that is built into T4 templating engine. If you need access the current project you may try this:
var dte = (EnvDTE.DTE)((IServiceProvider)Host).GetService(typeof(EnvDTE.DTE));
var project = dte.Solution.FindProjectItem(Host.TemplateFile).ContainingProject;
Don't forget to import the assembly at the top of your T4 template:
<#@ assembly name="EnvDTE" #>
I know VisualStudioHelper
from tangible's T4 Editor. It is free and comes with a template gallery providing useful T4 templates you can include in yours e.g. for accessing Visual Studio functionality or project configuration etc.
Maybe you should have a look there.
Edit: The template you should be looking for in the gallery is named "tangible Visual Studio Automation Helper"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With