1

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.

3
  • How does it relate to a devops culture or tooling ? This sounds just a programming question...
    – Tensibai
    Sep 13, 2017 at 8:55
  • You don't feel this is a devops question? DevOps includes builds and automation. Specifically this question is related to tools and infrastructure as code. Looking around devops.stackexchange there are several questions relating to automation, builds, jenkins, etc. It does cross the line, but when I think of infrastructure as code, I think devops rather than a stackoverflow question.
    – nichos
    Sep 13, 2017 at 15:42
  • That's highly unclear from your question actually what the goal of this MSbuild is. Keep in mind that's your responsibility to avoid misconception when asking your tags are very vague and your question doesn't explain it is for infrastructure in any way
    – Tensibai
    Sep 13, 2017 at 15:54

1 Answer 1

0

This question was kindly answered on StackOverflow. For anyone else looking for an answer:

<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)" />

source: https://stackoverflow.com/questions/46226120/how-to-pass-dynamic-properties-to-an-msbuild-task

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.