void OnProjectItemAdded(object sender, ProjectItemEventArgs e)
        {
            if (e.Project != project)
            {
                return;
            }

            ReferenceProjectItem reference = e.ProjectItem as ReferenceProjectItem;

            if (reference != null)
            {
                if (reference.ItemType == ItemType.COMReference)
                {
                    System.Windows.Forms.MethodInvoker action = delegate {
                        // Compile project to ensure interop library is generated
                        project.Save();                         // project is not yet saved when ItemAdded fires, so save it here
                        TaskService.BuildMessageViewCategory.AppendText("\n${res:MainWindow.CompilerMessages.CreatingCOMInteropAssembly}\n");
                        BuildCallback callback = delegate {
                            System.Threading.ThreadPool.QueueUserWorkItem(AddReference, reference);
                            lock (callAfterAddComReference) {
                                if (callAfterAddComReference.Count > 0)
                                {
                                    callAfterAddComReference.Dequeue()();
                                }
                                else
                                {
                                    buildingComReference = false;
                                }
                            }
                        };
                        project.StartBuild(new BuildOptions(BuildTarget.ResolveComReferences, callback));
                    };
                    lock (callAfterAddComReference) {
                        if (buildingComReference)
                        {
                            callAfterAddComReference.Enqueue(action);
                        }
                        else
                        {
                            buildingComReference = true;
                            action();
                        }
                    }
                }
                else
                {
                    System.Threading.ThreadPool.QueueUserWorkItem(AddReference, reference);
                }
            }
            if (e.ProjectItem.ItemType == ItemType.Import)
            {
                UpdateDefaultImports(project.Items);
            }
            else if (e.ProjectItem.ItemType == ItemType.Compile)
            {
                if (System.IO.File.Exists(e.ProjectItem.FileName))
                {
                    ParserService.EnqueueForParsing(e.ProjectItem.FileName);
                }
            }
        }
Exemple #2
0
        void OnProjectItemAdded(object sender, ProjectItemEventArgs e)
        {
            if (e.Project != project)
            {
                return;
            }

            ReferenceProjectItem reference = e.ProjectItem as ReferenceProjectItem;

            if (reference != null)
            {
                if (reference.ItemType == ItemType.COMReference)
                {
                    System.Windows.Forms.MethodInvoker action = delegate {
                        // Compile project to ensure interop library is generated
                        project.Save();                         // project is not yet saved when ItemAdded fires, so save it here
                        TaskService.BuildMessageViewCategory.AppendText("\n${res:MainWindow.CompilerMessages.CreatingCOMInteropAssembly}\n");
                        BuildCallback afterBuildCallback = delegate {
                            lock (callAfterAddComReference) {
                                if (callAfterAddComReference.Count > 0)
                                {
                                    // run next enqueued action
                                    callAfterAddComReference.Dequeue()();
                                }
                                else
                                {
                                    buildingComReference = false;
                                    ParserService.Reparse(project, true, false);
                                }
                            }
                        };
                        BuildEngine.BuildInGui(project, new BuildOptions(BuildTarget.ResolveComReferences, afterBuildCallback));
                    };

                    // enqueue actions when adding multiple COM references so that multiple builds of the same project
                    // are not started parallely
                    lock (callAfterAddComReference) {
                        if (buildingComReference)
                        {
                            callAfterAddComReference.Enqueue(action);
                        }
                        else
                        {
                            buildingComReference = true;
                            action();
                        }
                    }
                }
                else
                {
                    ParserService.Reparse(project, true, false);
                }
            }
            if (e.ProjectItem.ItemType == ItemType.Import)
            {
                UpdateDefaultImports(project.Items);
            }
            else if (e.ProjectItem.ItemType == ItemType.Compile)
            {
                if (System.IO.File.Exists(e.ProjectItem.FileName))
                {
                    ParserService.EnqueueForParsing(e.ProjectItem.FileName);
                }
            }
        }