MSBuild task to execute an external MSBuild file

msbuild

I'm trying to set up a MSBuild file which will invoke another MSBuild file and I'm wondering what's the best way to achieve this.

We're using it in the scenario of where a build server downloads a MSBuild file which then depending on the parameters it'll execute the appropriate 2nd file.

I know I can just use the <Exec Command="msbuild.exe ..." /> task, but that seems to be a bit of a hacky way to do it.

Is there an easier way to use MSBuild to execute another MSBuild file?

Best Answer

You can use the MSBuild task to build a target in another MSBuild project.

You can also put the target in an external .targets file that is imported by both MSBuild projects and use the CallTarget task to build it.

Update: To execute an external command, use the Exec task.

Related Topic