public override bool Execute() { AppDomain domain = null; bool success; try { AppDomainSetup info = new AppDomainSetup { ApplicationBase = BuildTaskPath, LoaderOptimization = LoaderOptimization.MultiDomainHost, ShadowCopyFiles = "true" }; string friendlyName = "GoClassGenerationDomain_" + Guid.NewGuid(); domain = AppDomain.CreateDomain(friendlyName, AppDomain.CurrentDomain.Evidence, info, new NamedPermissionSet("FullTrust"), new StrongName[0]); GoClassGenerationTaskInternal wrapper = CreateBuildTaskWrapper(domain); success = wrapper.Execute(); if (success) { _generatedCodeFiles.AddRange(wrapper.GeneratedCodeFiles.Select(file => (ITaskItem) new TaskItem(file))); } foreach (BuildMessage message in wrapper.BuildMessages) { ProcessBuildMessage(message); } } catch (Exception exception) { if (IsFatalException(exception)) { throw; } ProcessExceptionAsBuildMessage(exception); success = false; } finally { if (domain != null) { AppDomain.Unload(domain); } } return(success); }
private GoClassGenerationTaskInternal CreateBuildTaskWrapper(AppDomain domain) { GoClassGenerationTaskInternal wrapper = (GoClassGenerationTaskInternal)domain.CreateInstanceAndUnwrap(Assembly.GetExecutingAssembly().FullName, typeof(GoClassGenerationTaskInternal).FullName); IList <string> sourceCodeFiles = null; if (this.SourceCodeFiles != null) { sourceCodeFiles = new List <string>(SourceCodeFiles.Length); foreach (ITaskItem taskItem in SourceCodeFiles) { sourceCodeFiles.Add(taskItem.ItemSpec); } } wrapper.GoCompilerPath = GoCompilerPath; wrapper.SourceCodeFiles = sourceCodeFiles; wrapper.Language = Language; wrapper.OutputPath = OutputPath; wrapper.RootNamespace = RootNamespace; wrapper.GeneratedSourceExtension = GeneratedSourceExtension; return(wrapper); }