Question

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?

No correct solution

OTHER TIPS

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" #>

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"

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top