Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I pass a property to MSBuild via command line that could be parsed into an item group?

Tags:

msbuild

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

like image 768
Igor Pashchuk Avatar asked May 18 '11 21:05

Igor Pashchuk


People also ask

How use MSBuild command line?

To run MSBuild at a command prompt, pass a project file to MSBuild.exe, together with the appropriate command-line options. Command-line options let you set properties, execute specific targets, and set other options that control the build process.

How do I set properties in MSBuild?

MSBuild lets you set properties on the command line by using the -property (or -p) switch. These global property values override property values that are set in the project file. This includes environment properties, but does not include reserved properties, which cannot be changed.

How do I get MSBuild command from Visual Studio?

To install MSBuild on a system that doesn't have Visual Studio, go to Build Tools for Visual Studio 2019, or install the . NET SDK. If you have Visual Studio, then you already have MSBuild installed. With Visual Studio 2022, it's installed under the Visual Studio installation folder.

What is switch in MSBuild?

When you use MSBuild.exe to build a project or solution file, you can include several switches to specify various aspects of the process. Every switch is available in two forms: -switch and /switch. The documentation only shows the -switch form. Switches are not case-sensitive.


1 Answers

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 
like image 52
Brian Kretzler Avatar answered Sep 25 '22 19:09

Brian Kretzler