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:"$(InstallDir)\Environments\$(ApplicationName).EnvironmentSettings.xml""/>
<XmlPreprocessArgs Include="/i:"$(InstallDir)\UI.Shell.exe.config%3B$(InstallDir)\ClientLogging.config""/>
<XmlPreprocessArgs Include="/e:"$(Environment)""/>
</ItemGroup>
<Exec Command=""$(InstallDir)\Environments\XmlPreprocess.exe" @(XmlPreprocessArgs,' ')"
WorkingDirectory="$(InstallDir)\Environments" />