Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make a target run once at the Solution level in MSBuild

Tags:

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?

like image 512
Chandam Avatar asked Mar 16 '10 13:03

Chandam


People also ask

How do you build specific targets in solutions using MSBuild EXE?

To build a specific target of a specific project in a solution. At the command line, type MSBuild.exe <SolutionName>. sln , where <SolutionName> corresponds to the file name of the solution that contains the target that you want to execute.

Will MSBuild compile without any target?

If MSBuild determines that any output files are out of date with respect to the corresponding input file or files, then MSBuild executes the target. Otherwise, MSBuild skips the target. After the target is executed or skipped, any other target that lists it in an AfterTargets attribute is run.

What is an MSBuild target?

A target element can have both Inputs and Outputs attributes, indicating what items the target expects as input, and what items it produces as output. If all output items are up-to-date, MSBuild skips the target, which significantly improves the build speed. This is called an incremental build of the target.


1 Answers

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>

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.

like image 184
Sayed Ibrahim Hashimi Avatar answered Sep 22 '22 19:09

Sayed Ibrahim Hashimi