51

I have the following MSBuild script:

<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Main" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">    
  <PropertyGroup>
    <build_configurations>test1;test2;test3</build_configurations>
  </PropertyGroup>    
  <ItemGroup>
    <BuildConfigurations Include="$(build_configurations)" />
  </ItemGroup>    
  <Target Name="Main">    
    <Message Text="Running with args: %(BuildConfigurations.Identity)" />
  </Target>
</Project>

If I invoke the script without any parameters, I get the expected response:

Running with args: test1
Running with args: test2
Running with args: test3

However, when I attempt to set the property via command-line like so:

msbuild [myscript] /p:build_configurations=test5%3btest6%3btest7

I get the following:

Running with args: test5;test6;test7

So, it's not batching as expected. I need to get MSBuild to create the item group with three items instead of one item. How should I do that? Thanks.

P.S. The following article basically addresses my question except the case where I want to pass semicolon-separated values: http://sedodream.com/CommentView,guid,096a2e3f-fcff-4715-8d00-73d8f2491a13.aspx

Igor Pashchuk
  • 2,455
  • 2
  • 22
  • 29

1 Answers1

56

You've escaped the semicolons, preventing MSBuild from parsing them as individual items. Run like this instead, with quotes,

msbuild [myscript] /p:build_configurations="test5;test6;test7"

you will get the following output,

Running with args: test5
Running with args: test6
Running with args: test7
Brian Kretzler
  • 9,748
  • 1
  • 31
  • 28
  • 1
    This may have [broken](https://github.com/dotnet/msbuild/issues/471) in MSBuild. PowerShell workaround seems to be ``/p:build_configurations=\`"test5`;test6\`"`` (slash and backtick before quotes, backtick before semicolon). For Cmd, `/p:build_configurations=\"test5;test6\"` (slash before quote). – Vimes Jun 03 '22 at 23:56