问题描述:

We are having x, y ,z properties files and having a master.properties file

Now , i have written in my master.properties file some itemgroup like follows and pass this itemgroup to msbuild target so that it will work like foreach.

Item group:

 <Components Include="Y:\Build\X.Properties">

<ComponentName>X</ComponentName>

</Components>

<Components Include="Y:\Build\Y.Properties">

<ComponentName>Y</ComponentName>

</Components>

<Components Include="Y:\Build\Z.Properties">

<ComponentName>Z</ComponentName>

</Components>

<Target Name="BuildAll" Inputs="@(Components)" Outputs="%(Identity).Dummy">

<MSBuild Projects="@(Components)"

Targets="BuildComponent" />

</Target>

Now I want to have a txt file where component names will be given like this

X

Y

it should build only X and Y alone.

I was trying with ReadLinesFromFile , but i am not able to pass one by one component.

For ex:

 <ReadLinesFromFile File="Allcomponent.txt">

<Output TaskParameter="Lines" ItemName="AllComponent" />

</ReadLinesFromFile>

Then I want to pass component in the itemgroup one by one to call Msbuild tasks.

How to solve this?

网友答案:

Your question is not very clear, especially after "i am not able to pass one by one component".

You can access custom metadata for each item in an ItemGroup like this:

<Target Name="BuildAll" Inputs="@(Components)" Outputs="%(Identity).Dummy">
    <MSBuild Projects="%(Identity)" 
             Targets="%(ComponentName)" />
</Target>
网友答案:

Finally i found the solution. The solution is like below

I should create property with Component names.

<X>Y:\Build\X.Properties</X>
<Y>Y:\Build\Y.Properties</Y>
<Z>Y:\Build\Z.Properties</Z>

And in Msbuild task , I should follow as below

<Target Name="BuildAll" >

    <ReadLinesFromFile  File="$(AllComponents)">
      <Output TaskParameter="Lines" ItemName="AllComponents"/>
    </ReadLinesFromFile>

    <MSBuild Projects="$(%(AllComponents.Identity))"

             Targets="BuildComponent" />

</Target>

Now it will build the component which i pass through the text file.

相关阅读:
Top