本文介绍了如何通过命令行将可以解析为项目组的属性传递给 MSBuild?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下 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.

附言以下文章基本上解决了我的问题,除了我想传递分号分隔值的情况:http://sedodream.com/CommentView,guid,096a2e3f-fcff-4715-8d00-73d8f​​2491a13.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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 17:19