visual studio extensions - How can I run custom tool or save a file programmatically using EnvDTE? -
i want save/run custom tools on handful of .tt
files extension. don't want loop on files in solution/project, rather want able use relative (or full) path of file execute save/run custom tool.
is there way projectitem
object given path of file ($(solutiondir)/myproject/myfile.tt
) can execute methods on it?
you can use findprojectitem
method of envdte.solution
type find file within current solution it´s name. executecommand
method dependent on current ui context; item must selected, otherwise call fails.
private bool tryexecutetexttemplate(string filename) { var dte = (dte2)this.getservice(typeof(sdte)); solution solution = dte.solution; if ((solution != null) && solution.isopen) { projectitem item = solution.findprojectitem(filename); if (item != null) { // todo: track item in solution explorer try { item.dte.executecommand("project.runcustomtool"); return true; } catch (comexception) { } } } return false; }
Comments
Post a Comment