Reputation: 157
Is it possible to pass a dynamic property group to an MSbuild task? So if I have the following properties and values:
<MyPropertyGroup>
<Foo>bar</Foo>
<Foo1>bar1</Foo1>
<Foo2>bar2</Foo2>
</MyPropertyGroup>
I could call MSBuild with a short property list:
<MSBuild Projects="$(SolutionFile)" Targets="Build" Properties="MyPropertyGroup" />
But it would be the same as calling the task like this:
<MSBuild Projects="$(SolutionFile)" Targets="Build" Properties="Foo=bar;Foo1=bar1;Foo2=bar2" />
This is helpful if there's a large property list, and allows for only 1 place needs to be maintained.
Upvotes: 1
Views: 1821
Reputation: 100543
There's two issues here:
<PropertyGroup>
element is only used to define properties. After evaluation, all properties are just a list of key-value pairs without any grouping, so even a <PropertyGroup Label="my groups">
has no effect on the properties it contains.The most practical solution to your problem is to define a single property that contains all the values:
<PropertyGroup>
<BuildParameters>
Configuration=Debug;
Platform=Any CPU;
SomeOtherProperty=Foo
</BuildParameters>
</PropertyGroup>
…
<PropertyGroup>
<!-- this property can even be extended afterwards, e.g. when a condition is needed -->
<BuildParameters Condition=" '$(ShallAppendThings)' == 'true' ">
$(BuildParameters);
AnotherProperty=SomeValue
</BuildParameters>
</PropertyGroup>
…
<MSBuild Projects="$(SolutionFile)" Targets="Build" Properties="$(BuildProperties)" />
Upvotes: 3