toptensoftware/PetaPoco — Issue #100: T4 Will Not Run if Project is Not Selected
Author: ianlee74
Created: 2012-02-23 16:36:08+00:00
State: open

If VS2010, if I try to run the T4 template and the project that contains the T4 template is not selected/highlighted then the template will throw an exception and will not run. To get around this, I have added the following line as a reminder but I suspect there is a more elegant solution that could be used based on discovering the name of the current project rather than looking for "active" projects.

In PetaPoco.Core.ttinclude...

public EnvDTE.Project GetCurrentProject() {
...
Array activeSolutionProjects = (Array)dte.ActiveSolutionProjects;
if (activeSolutionProjects == null)
throw new Exception("DTE.ActiveSolutionProjects returned null");

*** BEGIN: I ADDED THIS ***

if(activeSolutionProjects.Length == 0)
throw new Exception("You must select/click the project that is generating the POCOs before running the template.");

*** END: I ADDED THIS ***
...
}