I have msbuild tasks that execs out to powershell modules. One of the ps module functions I call accepts an array type as a input parameter so I'm doing something like this:
<Exec Command="powershell -ExecutionPolicy unrestricted -command "& {Import-Module $(MyPowerShellModule); $(TargetFunction) -AnArray %40('OneArrayItem')}" ContinueOnError="ErrorAndContinue" />
What I'd like to do is be able to define a native msbuild property to some value, e.g.,
<PSArrayValues>OneArrayItem;TwoArrayItem;ThreeArrayItem</PSArrayValues>
and essentially can be parsed in such a way that my original target would wind up looking like:
<Exec Command="powershell -ExecutionPolicy unrestricted -command "& {Import-Module $(MyPowerShellModule); $(TargetFunction) -AnArray %40('OneArrayItem&apos,'TwoArrayItem&apos,'ThreeArrayItem')}" ContinueOnError="ErrorAndContinue" />
What approach(es) may be used for this?
You need to use MSBuild's item list flattening feature. Normally that would separate items in an item group with
;
but you can change that to a,
like so@(PSArrayValues, ',')
/ Here is a test MSBuild project file that demonstrates this:This outputs:
Also note that your Exec command was missing the ending double quote after the last
}
.