/// <summary> /// Refreshes the project content for the specified reference if required. /// This method does nothing if the reference is not an assembly reference, is not loaded or already is up-to-date. /// </summary> public static void RefreshProjectContentForReference(ReferenceProjectItem item) { if (item is ProjectReferenceProjectItem) { return; } ProjectContentRegistry registry = GetRegistryForReference(item); registry.RunLocked( delegate { IProjectContent rpc = GetExistingProjectContentForReference(item); if (rpc == null) { LoggingService.Debug("RefreshProjectContentForReference: not refreshing (rpc==null) " + item.FileName); return; } if (rpc.IsUpToDate) { LoggingService.Debug("RefreshProjectContentForReference: not refreshing (rpc.IsUpToDate) " + item.FileName); return; } LoggingService.Debug("RefreshProjectContentForReference " + item.FileName); HashSet <IProject> projectsToRefresh = new HashSet <IProject>(); HashSet <IProjectContent> unloadedReferenceContents = new HashSet <IProjectContent>(); UnloadReferencedContent(projectsToRefresh, unloadedReferenceContents, registry, rpc); foreach (IProject p in projectsToRefresh) { ParserService.Reparse(p, true, false); } }); }
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); } } }