Visual Studio 2010 plugin / code for clearing the "Error list" warnings before each build

VS2010 annoys me: when I rebuild, the Error List warnings from the previous compilation are saved, and any new warnings are simply added to the end of the list. Over time, this list becomes ridiculously long and cumbersome.

I use Chirpy 2.0 tools to run JSHint and JSLint in my JS files, and these tools generate a lot of false positives.

I was looking for an easy way to clear the contents of this window , but the only manual mechanism that works 100% of the time is to close and reopen the solution. Not very elegant.

I would like to write a small VS Plug-In or some code that is called just before compilation to remove this list so that I can focus only on new warnings for the uploaded files (s).

I see the .Clear () method for the output window, but not for the error list. Is this doable?

+4
source share
1 answer

I was once a Add-In / VSIX / MEF developer ...

The answer is no soon, but I have to do it on a long way:

Add-ins, packages (managed or not) have access to the VS service level separately. Each error belongs to the reporter (if they manage it like Chirpy do), so you cannot handle errors created by Chirpy 2.0

I look at the source code several times and save it erros obtained by the tools in the Singleton collection called TaskList.

Collection items are deleted at several points in the latest version using the RemoveAll method:

  • First: after the closure of the soul.

  • :

private static string[] buildCommands = new[] { "Build.BuildSelection", "Build.BuildSolution", "ClassViewContextMenus.ClassViewProject.Build" };

  private void CommandEvents_BeforeExecute(string guid, int id, object customIn, object customOut, ref bool cancelDefault) { EnvDTE.Command objCommand = default(EnvDTE.Command); string commandName = null; try { objCommand = this.App.Commands.Item(guid, id); } catch (System.ArgumentException) { } if (objCommand != null) { commandName = objCommand.Name; var settings = new Settings(); if (settings.T4RunAsBuild) { if (buildCommands.Contains(commandName)) { if (this.tasks != null) { this.tasks.RemoveAll(); } Engines.T4Engine.RunT4Template(this.App, settings.T4RunAsBuildTemplate); } } } } 

As you can see, exclusion of results depends on many topics. First in the setup (which I don’t know where to install the GUI or configs, but it seems that its value is a checkbox). The second array of names that do not contain each build command name.

So, I see a solution, but only on how to modify and rebuild / remake my own version with Chirpy (and make a Pull request):

The code cannot depend on commands and their names. (e.g. no rebuilds)

You can change the method above like this:

 this.eventsOnBuild.OnBuildBegin += ( scope, action ) => { if (action != vsBuildAction.vsBuildActionDeploy) { if (this.tasks != null) { this.tasks.RemoveAll(); } if (settings.T4RunAsBuild && action != vsBuildAction.vsBuildActionClean) { Engines.T4Engine.RunT4Template(this.App, settings.T4RunAsBuildTemplate); } } }; 

Or with something equivalent to a handler method instead of a lambda expression. You added it to the OnStartupComplete subscription method of the Chirp class.

Unsubscribing must be placed in the OnDisconnection method in the same class. (As with all other signed handlers ...)

Update:

When the add-in is disabled, this does not mean that Studio will be closed immediately. The add-in can be unloaded. Therefore, you should also call RemoveAll from OnDisconneconnection. (Or remove and remove ObjectList ...)

Update2:

You can also create a custom command and bind it to a hotkey.

+2
source

All Articles