使目标在MSBuild中的解决方案级别运行一次 [英] Make a target run once at the Solution level in MSBuild

查看:50
本文介绍了使目标在MSBuild中的解决方案级别运行一次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一组任务,对于整个解决方案,这些任务必须精确地执行一次.这将运行将修改每个项目的任务,以为每个项目运行一组单独的任务.我们之前使用解决方案级别任务的解决方案是一个单独的项目来完成此操作,但我们希望摆脱这个问题.有没有人做过或者对如何实现有任何建议?

I need a set of tasks that need to be executed exactly once for the entire solution. This will run tasks that will modify each project to run a separate set of tasks for each project. We had done this earlier using a separate project to the solution which had the solution level tasks, but we want to move away from that. Has anyone done this or does anyone have any suggestions on how to implement this?

推荐答案

由于解决方案文件不是MSBuild格式,因此不容易扩展或自定义.如果要对构建过程进行更多控制,则必须创建一个驱动程序" msbuild文件,该文件将替换您的解决方案文件.在此驱动程序文件中,您将构建所需的所有项目并执行一些其他任务.您可以使用 MSBuild任务完成此操作.这是一个示例,显示了如何构建多个项目.

Since Solution files are not in MSBuild format they are not easily extended or customized. If you want more control over the build process you would have to create a "driver" msbuild file which would replace your solution file. Inside this driver file you would build all the projects that you needed and perform some additional tasks. You would do this using the MSBuild task. Here is a sample showing how to build more than 1 project.

<Project ...>
    <ItemGroup>
        <Projects Include="proj01.csproj"/>
        <Projects Include="proj02.csproj"/>
        <Projects Include="proj03.csproj"/>
    </ItemGroup>

    <Target Name="BuildAll">
        <MSBuild Projects="@(Projects)" BuildInParallel="true" />
    </Target>

</Project>

因此,在您的情况下,您只需在构建项目之前执行任务即可.还要注意,我为BuildInParallel指定了true值,指示MSBuild可以一次尝试构建多个项目.

So in your case you would just execute the tasks before you build the projects. Also note that I specified the value true for the BuildInParallel indicating that MSBuild can try and build more than one project at once.

这篇关于使目标在MSBuild中的解决方案级别运行一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆