public static TaskRunnerResult Execute(string assemblyPath, string projectPath) { var assembly = Assembly.LoadFrom(assemblyPath); Dictionary <Type, IPostCompileTask> tasks = (from type in assembly.GetTypes() where typeof(IPostCompileTask).IsAssignableFrom(type) where !type.IsAbstract where type.HasDefaultConstructor() select type).ToDictionary(x => x, x => (IPostCompileTask)Activator.CreateInstance(x)); CheckTaskDependencies(tasks); List <IPostCompileTask> sortedTaskInstances = tasks.Values.TopologicalSort(x => x.DependsOn.Select(y => tasks[y])).ToList(); AnalyzerManager manager = new AnalyzerManager(); ProjectAnalyzer analyzer = manager.GetProject(projectPath); AdhocWorkspace workspace = analyzer.GetWorkspace(); Solution solution = workspace.CurrentSolution; var log = new ConcreteLog(solution, Console.Out); foreach (var taskInstance in sortedTaskInstances) { taskInstance.Log = log; taskInstance.RunAsync().Wait(); } // Return task types that need to be removed return(new TaskRunnerResult { TaskTypes = tasks.Select(x => x.Key.FullName).ToList() }); }
public TaskRunnerResult Execute(string assemblyPath, string solutionPath) { var assembly = Assembly.LoadFrom(assemblyPath); var tasks = (from type in assembly.GetTypes() where typeof(IPostCompileTask).IsAssignableFrom(type) where !type.IsAbstract where type.HasDefaultConstructor() select type).ToDictionary(x => x, x => (IPostCompileTask)Activator.CreateInstance(x)); CheckTaskDependencies(tasks); var sortedTaskInstances = tasks.Values.TopologicalSort(x => x.DependsOn.Select(y => tasks[y])).ToList(); var workspace = MSBuildWorkspace.Create(); var solution = workspace.OpenSolutionAsync(solutionPath).Result; var log = new ConcreteLog(solution, Console.Out); foreach (var taskInstance in sortedTaskInstances) { taskInstance.Log = log; taskInstance.RunAsync().Wait(); } // Return task types that need to be removed return(new TaskRunnerResult { TaskTypes = tasks.Select(x => x.Key.FullName).ToList() }); }