How to extract a directory from a property?

I have a property GroupProjthat saves the full path name. How can I extract a property directory?

I have the following code, but it does not work properly:

<PropertyGroup>
    <GroupProj>C:\development\project\default.groupproj</GroupProj> 
</PropertyGroup>

<Target Name="Default">
    <Message Text="Echo: $(GroupProj->'%(RootDir)')" />
</Target>

I will describe my actual intention to do this. Perhaps there is a way to do a job that I don't know about.

I have a project Delphigroupproj (MSBuild project) C:\development\project\default.groupproj:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <ItemGroup>
        <Projects Include="project1.dproj">
            <Dependencies/>
        </Projects>
        <Projects Include="project2.dproj">
            <Dependencies/>
        </Projects>
        <Projects Include="project3.dproj">
            <Dependencies/>
        </Projects>
    </ItemGroup>
    ...
</Project>

There are other 3 MSBuildfiles ( project1.dproj, project2.dprojand project3.dproj) stored in the same folder as default.groupproj.

I create a project file MSBuild(c: \ test.targets):

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build" ToolsVersion="3.5">
    <Import Project="$(GroupProj)" />
    <Target Name="Build">
        <MSBuild BuildInParallel="True" Projects="project1.dproj;project2.dproj;project3.dproj"/>
    </Target>
</Project>

And do as:

c:\> msbuild /p:GroupProj="C:\development\project\default.groupproj" test.targets

Execution is not performed because MSBuildit cannot find the file projectN.dproj. The problem is that the working directory is not installed on default.groupproj.

, $(GroupProj) concat projectN.dproj .

.

+4
1

- :

<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

    <PropertyGroup>
        <GroupProj>C:\development\project\default.groupproj</GroupProj> 
    </PropertyGroup>

    <Target Name="Build">
        <CreateItem Include="$(GroupProj)">
          <Output TaskParameter="Include" ItemName="ItemFromProp"/>
      </CreateItem>

      <Message Text="1. @(ItemFromProp -> '%(RootDir)%(Directory)')"/>
      <Message Text="2. %(ItemFromProp.RootDir)%(ItemFromProp.Directory)"/>
      <Message Text="3. %(ItemFromProp.Identity)"/>
      <Message Text="4. %(ItemFromProp.FullPath)"/>
      <Message Text="5. %(ItemFromProp.FileName)"/>
      <Message Text="6. %(ItemFromProp.Extension)"/>
    </Target>
</Project>

EDIT:

, :

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

  <Target Name="GetGroupProjPath">
    <ItemGroup>
      <GroupProj Include="$(GroupProj)" />
      <GroupProjPath Include="@(GroupProj->'%(Directory)')" />
    </ItemGroup>

    <PropertyGroup>
      <GroupProjPath>@(GroupProjPath->'%(RootDir)%(Identity)')</GroupProjPath>
    </PropertyGroup>
  </Target>

  <Import Project="$(GroupProj)" />
  <Target Name="GetDProjs" DependsOnTargets="GetGroupProjPath">
    <ItemGroup>
      <DProjs Include="@(Projects->'$(GroupProjPath)%(FileName)%(Extension)')" />
    </ItemGroup>
  </Target>

  <Target Name="Build" DependsOnTargets="GetDProjs">
    <Message Text="@(DProjs)" />
  </Target>
</Project>
+3

All Articles