Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

t4 "VisualStudioHelper" not found

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?

like image 200
Michel Fornaris Avatar asked Jul 16 '13 20:07

Michel Fornaris


3 Answers

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:

  1. Open Tangible T4 menu in Visual Studio and then click Template Gallery.
  2. Click "Update Now" icon from left-down corner.
  3. Choose from the directory tree: Tangible > Visual Studio CodeModel.
  4. In the files menu, right mouse button on "Walking the Visual Studio Code Model" and choose "Add to Solution..."
  5. Choose "VisualStudioHelper.ttinclude".
  6. In your .tt file refer to VisualStudioHelper as following:

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

like image 54
Dariusz Woźniak Avatar answered Nov 10 '22 22:11

Dariusz Woźniak


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" #>
like image 1
Pawel Avatar answered Nov 10 '22 22:11

Pawel


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"

like image 1
Nico Avatar answered Nov 10 '22 22:11

Nico