问题描述
我有以下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
我得到以下信息:
Running with args: test5;test6;test7
因此,它没有按预期进行批处理.我需要获得MSBuild才能创建包含三个项目而不是一个项目的项目组.我该怎么办?谢谢.
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.以下文章基本上解决了我的问题,除了我想传递以分号分隔的值的情况: http://sedodream.com/CommentView,guid,096a2e3f-fcff-4715-8d00-73d8f2491a13.aspx
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
推荐答案
您已对分号进行了转义,以防止MSBuild将其解析为单独的项目.而是这样运行,用引号引起来,
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"
您将获得以下输出,
Running with args: test5
Running with args: test6
Running with args: test7
这篇关于如何通过命令行将可以解析为项目组的属性传递给MSBuild?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!