Thursday, April 28, 2011

Managing Exec Commands with Arguments in MSBuild

I recently had to write an MSBuild Exec task to run the Visual Studio 2013 Code Metrics tool from the Command Line:

Unfortunately, the tool is solely managed via the Command Line and there does not appear to be any specialized  MSBuild Task for it.  Once I started digging into the syntax, I encountered a problem with passing multiple files to the command since each file needs to be passed as a separate /file: parameter as outlined in this article:

When working with NAnt, this operation would have been relatively easy since the exec task in NAnt provides an arg parameter:

However, the MSBuild Exec task has no such arg parameter to accomplish this in just the same manner.

Fortunately, I found this blog posting which saved me a lot of grief and helped me to come with a suitable solution to run my Code Metrics via the command line so I thought I would share it with anyone else who might need it as well:

The MSBuild trick that it utilizes leverages an ItemGroup and delimits the elements in the ItemGroup with a single blank space character ' '.  I found it extremely handy and hopefully you will too!

No comments:

Post a Comment