Friday, 27 July 2012

Adding an item to VisualStudio's Error List Window

I just spent a ridiculous amount of time trying to figure this out, so here is a solution for something that should be simple, I struggled to find a solution, but when I finally found the solution, it was not that bad.

Basically, what I'm trying to do is to add errors/items to the Error List in VisualStudio based on Code Analysis (either at solution or file level).

If you want to read the solution, it is here https://gist.github.com/3185313 (also included at the end of this post). This script was executed from an O2 REPL Script environment running inside VisualStudio.

The next text is from an email I wrote asking for help to a MS guru on VS Extensibility.

----start----

I was expecting this to be something like this (in pseudo C# code):

VisualStudio.Editor.OnTextChange(
      ()=>{ 
              var code = VisualStudio.Editor.GetCode();
              var errorListPane =  VisualStudio.ErrorPane;
              var issues = AnalyzeAndGetIssues(code);
              foreach(var issue in issues)
                   errorListPane.Add(issue.Text, issue.Span, issue.Severity)
          });

or even just simply:

VisualStudio.Editor.OnTextChange(
      (code)=>{ 
                  var issues = code.AnalyzeAndGetIssues();
                  VisualStudio.ErrorPane.add(issues)
              });

VisualStudio.Editor.OnCompile(
      (assemblies)=>{ 
                       var issues = assemblies.AnalyzeAndGetIssues();
                       VisualStudio.ErrorPane.add(issues)
                    });

Here is a thread about what I'm trying to do and with the same problems that I have: How to add parsing errors to ErrorList window?

Here is more information about what I have done already and what I can/can't do:

  • I have written an VS Add-in which gives me access to the DTE2 and AddIn objects inside a REPL environment on a running VisualStudio instance (think of it as a mix of Interactive Window + Roslyn REPL) 
  • I have a VSPackage/VSIX that gives me access to the Package object and MEF exports from a similar REPL environment. 
  • From the Addin I can create VisualStudio native dockable panels (with an WinForms or WPF control inside). Take a look at the video here http://diniscruz.blogspot.co.uk/2012/06/real-time-vulnerability-creation.html to see an Code Editor (from SharpDevelop) running natively in VisualStudio with a couple extra panels showing security vulnerabilities information (note that these controls are hosted natively in VisualStudio windows created using DTE's CreateToolWindow2 method) 
  • One of the problems I had was in gaining access to the live instance of the Error Panel, since in one of my tests I had the error: The service "Microsoft.VisualStudio.Shell.Interop.IVsTaskList" must be installed for this feature to work" 
  • I could try to access the actually ListView control via the WPF/WinForms GUI controls, but that would be a massive hack 
  • I was able to create a PoC that did exactly what I wanted using a variation of the Roslyn's CodeIssue example. This did exactly what I wanted since I had a callback from Roslyn that expected to receive a List of CodeIssue objects (which where then added to the VisualStudio Error List). I have looked at Roslyn code, but can't figure out its connection with the actually error list (there are too many layers of callbacks). 
  • One key objective that we have is to able to distribute our solution in one file installer. At the moment a VSIX seems like a perfect solution since it allows the easy distribution and install of VisualStudio plugins (vs the Addin model which requires the user to copy it to correct location)

----end----

Here are a number of  good resources on this topic (note: which helped find the solution):


solution

Friday, 20 July 2012

New O2 Feature to package scripts on WSDL and Notepad scripts

The latest version of O2 (all pushed to GitHub) contains a really powerful feature which is the ability to package most C# or H2 scripts as stand alone exes (i.e. 1 exe file with all dependencies)

You will find a new option on the invoke scripts popup and on the REPL editor which will fire up the 'exe creation workflow'

This means that from now on I will start publishing most O2 features and stand-alone tools, with the idea to create really powerful, useful, easy to use/deploy and focused tools.

To get you started, take a look at these 3 reddit posts:

FxCop Security rules : A nice to have feature on top of O2 platform

Check out this nice post from Michael Hidalgo on O2's blog : FxCop Security rules : A nice to have feature on top of O2 platform

And yes, I agree that we should add Fx-Cop to O2. 

So who wants to do it? This could actually be a good case study for how to add support for other tools to O2. I do this all the time, so it would be good if you guys also figured out how to do it too :)

Btw, if you want to write a blog post on the O2 Platform blog, let me know your wordpress account and I'll add you to it

Tuesday, 17 July 2012

Help in sorting out the Cat.NET's EnvDTE dependency

I've been under a rock for the past month coding away (more details later) and one of the modules I created was a stand-alone O2 Tool (one file) that exposes the Cat.NET engine outside VisualStudio.

You can get it from the latest version of O2 (GitHub) or from this DropBox download: Tool - Cat.Net outside VisualStudio v1.3.exe

You can see below how it is supposed to work, but I'm having an issue at the moment which would be great if somebody could help in.

Basically the problem is that there is an dependency on EnvDTE which only happens on certain installs.

I have been able to run this tool on VMs with and without VisualStudio installed, so there must be something else that installs EnvDTE on a box (like the one I was using at EC2).

The problem is that one of my users is not able to run the O2 scripts based on the O2's Cat.NET APIs, and we need to figure out what needs to be added (or removed) in order to make this work.