MonoDevelop.Projects.Project GetProject (Mono.TextEditor.Document doc) { // There is no reference between document & higher level infrastructure, // therefore it's a bit tricky to find the right project. MonoDevelop.Projects.Project project = null; var view = doc.Annotation<MonoDevelop.SourceEditor.SourceEditorView> (); if (view != null) project = view.Project; if (project == null) { var ideDocument = IdeApp.Workbench.GetDocument (doc.FileName); if (ideDocument != null) project = ideDocument.Project; } if (project == null) project = IdeApp.Workspace.GetProjectContainingFile (doc.FileName); return project; }