mbergal
mbergal

Reputation: 664

Checking if project has a specific target in MSBuild

Some of my .csproj project files have special target "AssembleJS" that merges all .js files included in project in one big file (i.e. webcontrols.csproj has target "AssembleJS" with output "webcontrols.js").

So if I have project parts.csproj

  1. That has target AssembleJS.
  2. References project webcontrols.csproj.
  3. References utility project utils.csproj that does not have any JavaScript and does not have AssembleJS target.

I want target AssembleJS of parts.csproj execute AssembleJS in webcontrols.csproj (the same was as MSBuild works with standard Build target).

Something like

<MSBuild Project="@ReferencedProjects" Targets="AssembleJS"/> 

does not work because utils.csproj does not have target AssembleJS.

Is there any way to filter @ReferencedProjects based on whether project has certain target?

Any other idea on how to handle this scenario?

Upvotes: 1

Views: 523

Answers (1)

Sayed Ibrahim Hashimi
Sayed Ibrahim Hashimi

Reputation: 44312

You cannot do what you are requiring. But you might be able to acheive it with batching.

<Project xmlns=''>
    <ItemGroup>
        <ReferencedProjects Include="webcontrols.csproj">
            <Type>Web</Type>
        </ReferencedProjects>
        <ReferencedProjects Include="utils.csproj">
            <Type>NonWeb</Type>
        </ReferencedProjects>
    </ItemGroup>

   <Target Name="BuildWebProjects">
        <MSBuild Projects="@(ReferencedProjects)" Condition=" '%(ReferencedProjects.Type)' == 'Web' " />
   </Target>

</Project>

Do a search for MSBuild Batching and find some results on sedodream.com for more info.

Should I expand on this?

Upvotes: 2

Related Questions