2
votes

Assuming the latest version of MSBuild, let's say I have 3 projects ProjA, ProjB and ProjC. I have a custom target in A and B that copy the individual outputs (bin items) into a custom path $(CustomOutputPath) - this all works fine individually. ProjC also has a custom target but in addition to copying its files to $(CustomOutputPath), it also cleans up the output path first, then chains ProjA and ProjB so that essentially all 3 projects have their files in the custom output path.

Let's assume I cannot change this requirement.

My ProjC target looks something like this:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

    <!-- Contains groups and properties only like 
         CustomOutputPath and BuildProjects -->
    <Import Project="SharedGroups.msbuild"/>

    <Target Name="AfterBuild">

        <!-- Removing old output -->
        <RemoveDir Directories="$(CustomOutputPath)" />

        <ItemGroup>
            <!-- Arbitrary contents of this project -->
            <FilesToCopy Include="**\*.*" /> 
        </ItemGroup>

        <!-- this works fine -->
        <Copy SourceFiles="@(FilesToCopy)"
              DestinationFolder="$(CustomOutputPath)"
              OverwriteReadOnlyFiles="true" />

        <!-- Once cleanup and copy is completed, I want to run all the other 
             projects builds which contain similar but specific copy tasks as 
             above, with no clean up. BuildProjects is an ItemGroup of all 
             the projects I want to build -->
        <MSBuild Projects="@(BuildProjects)" 
                 Properties="Configuration=$(Configuration); BuildProjectReferences=true"/>

    </Target>

</Project>

The problem I'm having is that one of the projects I am trying to build in the last step is failing because it references another project in the solution, which is not being built as part of the BuildProjectReferences=true directive, so it can't find the DLL. If I build this dependency individually then the MSBuild task will work, but I don't want to have to build this project independently.

Why is my referenced project not being built and is there a better way to do this with MSBuild?

Note: I am open to other solutions - I have tried to make ProjA and ProjB references of ProjC (hence not needing the MSBuild task at the bottom of ProjC target) but then the cleanup step in C happens AFTER A and B copy their output out so that doesn't work.

1

1 Answers

0
votes

Use /verbosity:detailed and redirect output to a file. Look through the verbiage to see what's happening with the ResolveProjectReferences target. You can also use /verbosity:diag and see details of why is skipped things etc. That might be useful since the Condition on the various tasks used there are pretty hairy.