T4 "VisualStudioHelper" not found

I am trying to do some experiments with generating code from VS2012 projects, but I cannot get this part of t4 code to work

var project = VisualStudioHelper.CurrentProject; 

since VisualStudioHelper could not be found.

What should I install / enable in my t4 to create a VisualStudioHelper?

+6
source share
3 answers

VisualStudioHelper is a custom class from the Tangible T4 Editor.

To use this class, install the Tangible T4 Editor for your Visual Studio, and then:

  • Open the Tangible T4 menu in Visual Studio and select Template Gallery.
  • Click the Update Now icon in the lower left.
  • Select from the directory tree: Tangible> Visual Studio CodeModel.
  • In the file menu, right-click on "Walk through the Visual Studio Code Model" and select "Add to Solution ..."
  • Select "VisualStudioHelper.ttinclude".
  • In your .tt file, refer to VisualStudioHelper as follows:

<#@ include file="VisualStudioHelper.ttinclude" #>

+8
source

What is a VisualStudioHelper ? This seems to be a common thing, not something that is built into the T4 templating engine. If you need access to the current project, you can try the following:

 var dte = (EnvDTE.DTE)((IServiceProvider)Host).GetService(typeof(EnvDTE.DTE)); var project = dte.Solution.FindProjectItem(Host.TemplateFile).ContainingProject; 

Remember to import the assembly at the top of your T4 template:

 <#@ assembly name="EnvDTE" #> 
+1
source

I know VisualStudioHelper from the T4 material editor . It's free and comes with a template gallery that contains useful T4 templates that you can include in yours, for example. to access Visual Studio features or project configuration, etc.

Perhaps you should look there.

Edit: The template you should look for in the gallery is called the "tangible Visual Studio Automation Assistant"

+1
source

Source: https://habr.com/ru/post/949594/


All Articles