You can search the Finance and Operations XML files (the X++ source code) using regular expressions by using PowerShell’s Select-String command.  This is a strategy that I’ve used many times and I wonder if others have realized the ease of approaching code searches this way.

For some background, we’ll be using regular expressions which provide a very flexible approach for searching (“matching”) text within files.  Grep, the Powershell Way is one of my frequently referred-to blog posts (not authored by me), because I am someone who had used Linux (Ubuntu, Debian, …FreeBSD) at home and now wanted to use the already-installed PowerShell commands to search the contents of files.  RegexBuddy has been my favorite regular expression tool ever since using it to code an ASP.NET product configurator in 2004.  It takes your regular expression and can convert it to the language you want (C#, PowerShell, Python, and like 20 others).  It is a solid program with frequent updates and it even allows you to grep for files without copying and pasting the file into PowerShell (of course testing your regex is built-in).  I’m not getting paid for this endorsement, it is just a very useful utility program even for those of us very comfortable with regular expressions.

During a Dynamics AX 2012 upgrade, I was curious how many TODOs were listed inside of the code because there were TODOs in the 2012 code that we being upgraded, as well as new TODOs added from the team was doing the code upgrade.

Open PowerShell as Administrator and run the following:

cd "C:\AOSService\PackagesLocalDirectory" # Or K:\ or J:\ depending on the dev environment
Get-ChildItem .\MY_CUSTOM_PACKAGE\* -Recurse -Include *.xml | Select-String -Pattern "// *TODO" | Set-Content -Path "$home\Desktop\TODOs in the Code.txt"

The command will match any todo comment and save it to a file on your desktop.  The TODO comments must be formatted similar to:

//TODO: XXX
//TODO XXX
//   TODO: XXX
// TODO XXX

The colon and number of spaces do not matter because of our Regex’s asterisk (*)- hurray!  Here is an example:

It found both of these TODO comments:

So you now have all the objects listed which require some additional thought- to determine if there is an actual action required or if the TODO task can be deleted from the source code.  Naturally I found over 500 of these in the code base I’m upgrading.  Now the real work begins!