How to batch in MSBuild?
msbuild
Solution
I think you want to do something like this:
<ItemGroup>
<Messages Include="Message1">
<Text>Hello from Message1</Text>
</Messages>
<Messages Include="Message2">
<Text>Hello from Message2</Text>
</Messages>
</ItemGroup>
<Target Name="TestMessage">
<Message Text="%(Messages.Text)"/>
</Target>
This produces the following output:
TestMessage:
Hello from Message1
Hello from Message2
Problem
I can't figure out how to pass values into an MSBuild task like I would a method. Take the following project file... ``` <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0" DefaultTargets="Main"> <PropertyGroup> <Var1>Foo</Var1> <Var2>Bar</Var2> </PropertyGroup> <Target Name="Main"> <Message Text="$(Var1)" Importance="high" /> <Message Text="$(Var2)" Importance="high" /> </Target> </Project> ``` I want to refactor the Message task into a target and then pass over Var1 and Var2 to it to get the same output. This is a very simplified example but the concept is the same.