Tuesday, June 9, 2015

Parsing msbuild output through RegEx

I wanted to be able to parse the output from msbuild to extract errors and warnings from both Microsoft and third party tools.

I found several posts describing the format of messages compliant with msbuilds parsing of errors and warnings but I could not find a regular expression that would do the same thing.

msbuild visual studio aware error messages and message formats

So I worked one out that I think works in most cases

const RegexOptions OPTIONS = RegexOptions.Compiled |
RegexOptions.IgnoreCase |
RegexOptions.IgnorePatternWhitespace |
RegexOptions.ExplicitCapture |
RegexOptions.Singleline;

// in multi-line $ == LF but not CR so use [^\r\n]+
const string PATTERN = @"
# token to match microsoft standard error format for tools
(^(
((?
(?:(?:[a-z]:|\\\\[a-z0-9_.$-]+\\[a-z0-9_.$-]+)\\| # Drive or UNC
\\?[^\\/:*?<>|\r\n]+\\?)                          # Relative path
(?:[^\\/:*?<>|\r\n]+\\)*                          # Folder
[^\\/:*?<>|\r\n]*                                    # File name
(\((?\d)(,(?\d))?\)?:)?         # (line#[,col#]) - optional
|(?\w)):\s?)?                                # or toolname
(\w+\s)?                                                 # optional severity
(?error|warning)                        # error or warning
(\s\w+\d)?                                              # error code - optional
:\s*                                                         # white space
(?.*$))                                  # error message
)
";

It looks really scary but it is reasonably simple if you take it a chunk at a time.

Named captures:
- the file the error happened in (optional)
- the line information (optional)
- the column (optional)
- the tool throwing the error (optional)
- the error level 
- the error message

Friday, November 15, 2013

My first battle with virus's on Windows 8

One of my friends invited me around to dinner last night. My spider senses should have been tingling but I fell for it. After a plate of  fish n chips from the local chipper she dropped her new Windows 8 laptop into conversation and how it had been running super slow and spamming all her contacts from her hotmail account.

I have never disinfected Windows 8 before so am looking forward to battle. As "failure to prepare is preparing to fail" I am doing some web research into what I am likely to face.

Virus Protection

First surprise, since it is my default action with XP/Vista/Windows 7, is Microsoft Security Essentials is not available for Windows 8. It seems this fantastic free product has been integrated into Windows Defender on Windows 8/8.1. Good news since this is about the simplest Anti-Virus package for the technically impaired.

The biggest surprise is Windows 8 and 8.1 did not support scheduling of a virus scan. I can not expect my friends to manually run a scan regularly so I have to schedule a scan using the scheduler. Very useful information can be found in the link below.

Configure Windows Defender in Windows 8 and 8.1 

Microsoft Account vs Local Account

My friend told me she had used her own hotmail account when setting up and now could not figure out how to set it up so her son could use it without giving him access to her password. Apparently because Windows 8 is really an operating system for touch pads and not laptops it pulls the installer down the path of single sign on to the "cloud". Turns out it is possible to switch this off and to switch to another user if desired.

How to Switch from a Microsoft Account to a Local Account in Windows 8 and 8.1

Detecting Nasties

I used to use HiJackThis to detect if something dark was lurking but it has not been updated since XP and could not possibly cope with Windows 8. Apparently the current tool of choice is OTL or "Old Timers ListIt". This is available on Geeks To Go and is a scanner like HiJackThis but updated for Microsoft's latest operating systems.

OTL OldTimer's List-It (download)

It seems much more complicated than HiJackThis but I guess the job is harder. One thing that stands out is the script interface for scanning and removal.