Loren Halvorson's Blog

If your only tool is a hammer...

December 2008 - Posts

MSBuild trick for making <Exec> calls more maintainable

One of my pet peeves with MSBuild’s <Exec> task is how long the lines get when you have lots of arguments.

I ran across a trick yesterday in a blog comment made by someone named Romain and thought it was a very nice solution to this problem. When you expand items using this form @(items, ‘DELIMITER’), it allows you to specify a delimiter to use between the items. In the case of a command line, you use a space. Thanks Romain.

<ItemGroup>
  <XmlPreprocessArgs Include="/nologo"/>
  <XmlPreprocessArgs Include="/v"/>
  <XmlPreprocessArgs Include="/x:&quot;$(InstallDir)\Environments\$(ApplicationName).EnvironmentSettings.xml&quot;"/>
  <XmlPreprocessArgs Include="/i:&quot;$(InstallDir)\UI.Shell.exe.config%3B$(InstallDir)\ClientLogging.config&quot;"/>
  <XmlPreprocessArgs Include="/e:&quot;$(Environment)&quot;"/>
</ItemGroup>

<Exec Command="&quot;$(InstallDir)\Environments\XmlPreprocess.exe&quot; @(XmlPreprocessArgs,' ')"
      WorkingDirectory="$(InstallDir)\Environments" />

Posted: Dec 11 2008, 01:52 PM by lorenh | with 6 comment(s)
Filed under: ,
More Posts