public static void WriteError(string message, string fileName, int lineNumber = 0, int columnNumber = 0, string helpKeyword = null, TaskCategory taskCategory = TaskCategory.User, string projectFile = null, bool allowOpenFile = false, bool activatePane = true) { SimpleVsHierarchy hierarchyItem = projectFile != null ? new SimpleVsHierarchy(projectFile) : null; ErrorTask task = new ErrorTask { HierarchyItem = hierarchyItem, Category = taskCategory, Document = fileName, Line = lineNumber, ErrorCategory = TaskErrorCategory.Error, Text = message, Column = columnNumber, HelpKeyword = helpKeyword }; if (allowOpenFile) { task.Navigate += (sender, args) => VisualStudioDTE.TryOpenFile(fileName, lineNumber, hierarchyItem); } AddTask(task, activatePane); }
public static void TryOpenFile(string fileName, int lineNumber, SimpleVsHierarchy hierarchyItem) { var toOpen = fileName; if (!File.Exists(toOpen) && hierarchyItem != null) { var directoryName = Path.GetDirectoryName(hierarchyItem.ProjectFile); if (directoryName != null) { toOpen = Path.Combine(directoryName, fileName); if (!File.Exists(toOpen)) { toOpen = hierarchyItem.ProjectFile; } } } TryOpenFile(toOpen, lineNumber); }