public override void ExecuteRecursive(TaskExecutionNode node) { var task = (RunAssemblyTask)node.RemoteTask; var priorCurrentDirectory = Environment.CurrentDirectory; try { // Use the assembly in the folder that the user has specified, or, if not, use the assembly location var assemblyFolder = GetAssemblyFolder(TaskExecutor.Configuration, task); var assemblyPath = new AssemblyPath(Path.Combine(assemblyFolder, GetFileName(task.AssemblyLocation))); Environment.CurrentDirectory = assemblyFolder; var listener = new PerAssemblyRunListener(Server, task); var contextList = new List<string>(); node.Flatten(x => x.Children).Each(children => RegisterRemoteTaskNotifications(listener, children, contextList)); var runOptions = RunOptions.Custom.FilterBy(contextList); var appDomainRunner = new AppDomainRunner(listener, runOptions); if (TaskExecutor.Configuration.ShadowCopy) { string cachePath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); runOptions.ShadowCopyTo(cachePath); this.Server.SetTempFolderPath(cachePath); } appDomainRunner.RunAssembly(assemblyPath); } finally { Environment.CurrentDirectory = priorCurrentDirectory; } }
private static ExitCode RunAssembly(Assembly assembly, RunOptions runOptions) { ISpecificationRunListener listener = new BufferedAssemblyTeamCityReporter(WriteToTeamCity); ISpecificationRunner specificationRunner = new AppDomainRunner(listener, runOptions); specificationRunner.RunAssembly(new AssemblyPath(assembly.Location)); if (listener is ISpecificationResultProvider) { var errorProvider = (ISpecificationResultProvider) listener; if (errorProvider.FailureOccurred) return ExitCode.Failure; } return ExitCode.Success; }