MSBuild task to execute an external MSBuild file

自古美人都是妖i 提交于 2019-12-22 04:32:29

问题


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?


回答1:


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.




回答2:


It's not just prettier to use the <MSBuild> task rather than <Exec Command="msbuild.exe .."/>. It means that the single MSBuild process knows about all the projects being built, and there's no collisions; a particular project can't be being built by two threads at once. That's usually vital if you are building with "/m". There's some other advantages too, such as there being one set of loggers for the whole build.




回答3:


Response to Adam Oren's comment: Here's an example to execute an external file - in this case, it launches nunit. The %22 is for escaping, it means " so you can have spaces in your executable path.

<Exec Command="%22$(NUnit_Install_Directory)bin\net-2.0\nunit-console.exe%22 
/noshadow @(TestableAssemblies, ' ') /xml 
 $(BuildFilesPath)\NCover-NUnit-Results.xml" /> 

You don't need to use variables like I did, but I find that it makes your scripts more portable. $(NUnit_Install_Directory) is defined as

<PropertyGroup> 
   <NUnit_Install_Directory>c:\Program Files\NUnit 2.5.3\</NUnit_Install_Directory> 




回答4:


<Target Name="TA">
    <CallTarget Targets="TB"/>
</Target>

<Target Name="TB">
    <Message Text="TB..." />
</Target>


来源:https://stackoverflow.com/questions/1501930/msbuild-task-to-execute-an-external-msbuild-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!